Results 1 to 5 of 5

Thread: [RESOLVED] More Excel Macro Fun!

Hybrid View

  1. #1
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: More Excel Macro Fun!

    OK
    Assuming that you have moved the ID and Date columns to a new sheet, the following will index that sheet for you. You will need to change the reference for the rngDataTable variable.

    VB Code:
    1. Sub GrudgeIndex()
    2. Dim rngDataTable As Range
    3. Dim rngCell As Range
    4.    
    5.     'This is the 2 column range that contains the ID in
    6.     'the first column and the date in the second column
    7.     Set rngDataTable = ThisWorkbook.Worksheets(1).UsedRange
    8.    
    9.     'Note: I'm assuming that the range has already been sorted
    10.     'by ID then Date - If not you should insert a sort here
    11.    
    12.     'Loop through each PatientID cell
    13.     For Each rngCell In rngDataTable.Columns(1).Cells
    14.        
    15.         'I'm assuming that the 1st row contains headers
    16.         If rngCell.Row <> 1 Then
    17.            
    18.             'If the ID is different that the ID on the
    19.             'previous row, or the date is different from
    20.             'the date on the previous row
    21.             'we restart the index at 1
    22.             If rngCell.Value <> rngCell.Offset(-1, 0) _
    23.             Or rngCell.Offset(0, 1) <> rngCell.Offset(-1, 1) Then
    24.                 rngCell.Offset(0, 2).Value = 1
    25.            
    26.             'Otherwise we increment the index by 1
    27.             Else
    28.                 rngCell.Offset(0, 2).Value = rngCell.Offset(-1, 2).Value + 1
    29.             End If
    30.         End If
    31.     Next rngCell
    32.    
    33.    
    34.     Set rngDataTable = Nothing
    35. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  2. #2

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Re: More Excel Macro Fun!

    NICE.

    How much easier is life now!!

Posting Permissions

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



Click Here to Expand Forum to Full Width