Results 1 to 7 of 7

Thread: [RESOLVED] Small Excel Macros

  1. #1

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

    Resolved [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!

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

    Re: Small Excel Macros

    I assume you are working in Excel? If so, then this should do the first one.
    VB Code:
    1. Sub GrudgeCounter(ByRef GrudgeRange As Range)
    2. Dim rngCell As Range
    3.    
    4.     For Each rngCell In GrudgeRange
    5.         If rngCell.Row = 1 Then
    6.             rngCell.Offset(0, 1).Value = 1
    7.         ElseIf rngCell.Value <> rngCell.Offset(-1, 0) Then
    8.             rngCell.Offset(0, 1).Value = 1
    9.         Else
    10.             rngCell.Offset(0, 1).Value = rngCell.Offset(-1, 1).Value + 1
    11.         End If
    12.     Next rngCell
    13. 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

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

    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:
    1. Sub GrudgeFillInTheBlanks(SheetName As String)
    2. Dim rngCell As Range
    3.  
    4.     For Each rngCell In ActiveWorkbook.Worksheets(SheetName).UsedRange.Columns(1).Cells
    5.         If rngCell.Offset(0, 1).Value = "" Then
    6.             rngCell.Offset(0, 1).Value = rngCell.Value
    7.             rngCell.Value = rngCell.Offset(-1, 0).Value
    8.         End If
    9.     Next rngCell
    10. 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

  4. #4

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

    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?

  5. #5

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

    Re: Small Excel Macros

    Bump.

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

    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:
    1. Sub GrudgeFillInTheBlanks(ByRef rngGrudge As Range)
    2. Dim rngCell As Range
    3.  
    4.     For Each rngCell In rngGrudge.Cells
    5.         If rngCell.Offset(0, 1).Value = "" Then
    6.             rngCell.Offset(0, 1).Value = rngCell.Value
    7.             rngCell.Value = rngCell.Offset(-1, 0).Value
    8.         End If
    9.     Next rngCell
    10. End Sub
    Declan

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

  7. #7

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

    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
  •  



Click Here to Expand Forum to Full Width