|
-
Mar 9th, 2006, 10:18 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] More Excel Macro Fun!
Firstly, let me apologize for all of my "macro" posts the last few days. I could have merged them all into one but I had no idea that I was going to need more than one! If your out there DKenny you may be able to help since your solution yesterday is VERY similar to today's issue.
Okay, hopefully this is it.
I'm using Excel so I need a macro to do the following.
Lets' say I have the following data (Name, Patient ID, and Date)...
DAVID, 01251, 20051214
DAVID, 01251, 20051214
JOE, 05564, 20051215
ERIC, 06498, 20051215
ERIC, 06498, 20051216
Well, wherever the Patient and Date are the same I need to create an index.
So it would end up looking like...
DAVID, 01251, 20051214 ----> 1
DAVID, 01251, 20051214 ----> 2
JOE, 05564, 20051215 ----> 1
ERIC, 06498, 20051215 -----> 1
ERIC, 06498, 20051216 ------> 1
The index only increments if both the PATIENTID and NAME are the same.
Got me?
Thanks in advance for the help guys & gals.
-
Mar 9th, 2006, 10:38 AM
#2
Re: More Excel Macro Fun!
 Originally Posted by The_Grudge
Well, wherever the Patient and Date are the same I need to create an index.
So it would end up looking like...
ERIC, 06498, 20051215 -----> 1
ERIC, 06498, 20051216 ------> 1
The index only increments if both the PATIENTID and NAME are the same.
Which is it? Patient and Date (per the first statement) or PATIENTID and NAME (per the second statement).
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Mar 9th, 2006, 10:41 AM
#3
Thread Starter
Fanatic Member
Re: More Excel Macro Fun!
Wow.....I need to SLOOOOOW DOWNNNNNNN.
It's patient ID and Date.
NOTE:
My file actually contains 15 columns or so but I figured it would be easier to cut out the 2 columns I need onto their own sheet, get the indexes with a macro, and paste the indexes back into the original sheet. That way I don't have to worry about messing with the other columns.
-
Mar 9th, 2006, 11:17 AM
#4
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:
Sub GrudgeIndex()
Dim rngDataTable As Range
Dim rngCell As Range
'This is the 2 column range that contains the ID in
'the first column and the date in the second column
Set rngDataTable = ThisWorkbook.Worksheets(1).UsedRange
'Note: I'm assuming that the range has already been sorted
'by ID then Date - If not you should insert a sort here
'Loop through each PatientID cell
For Each rngCell In rngDataTable.Columns(1).Cells
'I'm assuming that the 1st row contains headers
If rngCell.Row <> 1 Then
'If the ID is different that the ID on the
'previous row, or the date is different from
'the date on the previous row
'we restart the index at 1
If rngCell.Value <> rngCell.Offset(-1, 0) _
Or rngCell.Offset(0, 1) <> rngCell.Offset(-1, 1) Then
rngCell.Offset(0, 2).Value = 1
'Otherwise we increment the index by 1
Else
rngCell.Offset(0, 2).Value = rngCell.Offset(-1, 2).Value + 1
End If
End If
Next rngCell
Set rngDataTable = Nothing
End Sub
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Mar 10th, 2006, 11:20 AM
#5
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|