|
-
Mar 8th, 2006, 11:30 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Small Excel Macros
I already posted about an Excel Macro in this forum, but this isn't really a duplicate post. I need 2 more macros that are really simple. I have VB coding experience, just no experience coding macros so that's why I'm coping out and getting help on here. So much faster!!
I need macros to do the following...maybe even ASAP utilities has something built in I don't know.
1) If I have a list of names I need to create an index. Let's say the sheet has (each value in it's own column)...
DAVID
DAVID
JOSH
JOSH
SUE
I need it to be
DAVID, 1
DAVID, 2
JOSH, 1
JOSH, 2
SUE, 1
Simple right? LOL
2) I have another sheet that looks like this...
DAVID 2020
2030
2040
But i need it to look like this
DAVID 2020
DAVID 2030
DAVID 2040
Basically just fill in the blanks.
Any help is appreciated!
-
Mar 8th, 2006, 11:38 AM
#2
Re: Small Excel Macros
I assume you are working in Excel? If so, then this should do the first one.
VB Code:
Sub GrudgeCounter(ByRef GrudgeRange As Range)
Dim rngCell As Range
For Each rngCell In GrudgeRange
If rngCell.Row = 1 Then
rngCell.Offset(0, 1).Value = 1
ElseIf rngCell.Value <> rngCell.Offset(-1, 0) Then
rngCell.Offset(0, 1).Value = 1
Else
rngCell.Offset(0, 1).Value = rngCell.Offset(-1, 1).Value + 1
End If
Next rngCell
End Sub
Last edited by DKenny; Mar 8th, 2006 at 12:11 PM.
Reason: Forgot to close the IF statement
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Mar 8th, 2006, 11:46 AM
#3
Re: Small Excel Macros
On your second question, it looks like the 2030 is in the same column as David and needs to be moved to the next column over. If this is true then the following will work.
VB Code:
Sub GrudgeFillInTheBlanks(SheetName As String)
Dim rngCell As Range
For Each rngCell In ActiveWorkbook.Worksheets(SheetName).UsedRange.Columns(1).Cells
If rngCell.Offset(0, 1).Value = "" Then
rngCell.Offset(0, 1).Value = rngCell.Value
rngCell.Value = rngCell.Offset(-1, 0).Value
End If
Next rngCell
End Sub
Last edited by DKenny; Mar 8th, 2006 at 12:13 PM.
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Mar 8th, 2006, 12:34 PM
#4
Thread Starter
Fanatic Member
Re: Small Excel Macros
Thanks for the help.
The 2030 is in the same column as DAVID for the second one, however there are more than just two columns. How do I deal with this if I need to fill in the blanks for multiple columns?
-
Mar 8th, 2006, 02:14 PM
#5
Thread Starter
Fanatic Member
Re: Small Excel Macros
Bump.
-
Mar 8th, 2006, 03:08 PM
#6
Re: Small Excel Macros
you could change the procedure, such that it takes a range as input and then call it for whatever number of ranges you need to change.
VB Code:
Sub GrudgeFillInTheBlanks(ByRef rngGrudge As Range)
Dim rngCell As Range
For Each rngCell In rngGrudge.Cells
If rngCell.Offset(0, 1).Value = "" Then
rngCell.Offset(0, 1).Value = rngCell.Value
rngCell.Value = rngCell.Offset(-1, 0).Value
End If
Next rngCell
End Sub
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:11 AM
#7
Thread Starter
Fanatic Member
Re: Small Excel Macros
Actually, in the free Excel Add-on called ASAP utilities there is a built in function to do this. God love that program.
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
|