Consulting

Results 1 to 5 of 5

Thread: help needed to adjust a macro

  1. #1
    VBAX Contributor
    Joined
    Feb 2008
    Posts
    193
    Location

    help needed to adjust a macro

    can somebody help me to adjust this macro. In the past the sheets where named 01 to 52. Now its wk01 to wk52. I cann't find a way to adjust the macro to get it work.
    PHP Code:

    Sub CreateXRef
    ()
        
    Dim i As LongAs LongAs Long
        Dim LastCol 
    As Long
        Dim LastRow 
    As Long
        Dim NextRow 
    As Long
        Dim FoundRow 
    As Long
        Dim sh 
    As Worksheet
         
        Application
    .ScreenUpdating False
         
        Application
    .DisplayAlerts False
        On Error Resume Next
        Worksheets
    ("output").Delete
        On Error 
    GoTo 0
        Application
    .DisplayAlerts True
         
        Set sh 
    Worksheets.Add(before:=Worksheets(1))
        
    sh.Name "output"
        
    sh.Range("A2").Value "Name:"
        
    NextRow 1
         
        
    For 1 To 52
        With Worksheets
    (Format(k"00"))
             For 
    2 To 8
                     
                    LastRow 
    = .Cells(.Rows.Countj).End(xlUp).Row
                    
    For 5 To LastRow
                     FoundRow 
    0
                        On Error Resume Next
                        FoundRow 
    Application.Match(.Cells(ij).Value2sh.Columns("B"), 0)
                        
    On Error GoTo 0
                        
    If FoundRow 0 Then
                             
                            NextRow 
    NextRow 1
                            sh
    .Cells(NextRow"B").Value2 = .Cells(ij).Value2
                            FoundRow 
    NextRow
                        End 
    If
                         
                        
    LastCol sh.Cells(FoundRowsh.Columns.Count).End(xlToLeft).Column
                        sh
    .Cells(FoundRowLastCol 1).Value2 CDate(.Cells(4j).Value2)
                        
    sh.Cells(FoundRowLastCol 1).NumberFormat = .Cells(4j).NumberFormat
                    Next i
                Next j
            End With
        Next k
         
        Application
    .ScreenUpdating True
         
    End Sub 
    Attached Files Attached Files

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Change:
    [vba] With Worksheets(Format(k, "00"))
    [/vba]
    to:
    [vba] With Worksheets("wk" & Format(k, "00"))
    [/vba]
    Be as you wish to seem

  3. #3
    VBAX Contributor
    Joined
    Feb 2008
    Posts
    193
    Location
    Thx for the quick help. This works.
    There is now a new problem. On page wk15 and further there is text on row 20. Now the macro gives on the sheet output the first date (15 times) of the week. I only need the names in rows 5 to 19 but if i adjust the macro


    LastRow = .Cells(.Rows.Count, j).End(xlUp).Row
    For i = 5 To LastRow

    to for I = 5 to 19 i get the first day of the week in the sheet output for every week 15 times.

    Ger

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    How about changing

    LastRow = .Cells(.Rows.Count, j).End(xlUp).Row
    to

    LastRow = .Cells(20, j).End(xlUp).Row
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Contributor
    Joined
    Feb 2008
    Posts
    193
    Location
    Thx.

    All works fine now.


    Ger

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •