INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Applying ID numbers to multiple rows

Applying ID numbers to multiple rows

(OP)
Hi,

I've not used VBA in a number of years and found myself needing to use it this afternoon and I've gone totally blank! and I'm really hoping one of you could help

I have an Excel sheet (see attached) where I have a membership number and on the same number there could be several people attached. The file I'm provided with details the number once and the people attached in the next column, there is then a break until the next member number. I need to populate the blank cells with the appropriate number.

I'm assuming a do loop until would do the trick, but, I'm falling short... If anyone could help I'd greatly appreciate it.

Many Thanks

RE: Applying ID numbers to multiple rows

Assuming you will always have a 'starting' value in A4:

CODE

Option Explicit

Sub DoIt()

Dim intRow As Integer
Dim intMNo As Integer

intRow = 4

Do While Range("B" & intRow).Value <> ""
    If Range("A" & intRow).Value = "" Then
        Range("A" & intRow).Value = intMNo
    Else
        intMNo = Range("A" & intRow).Value
    End If
    intRow = intRow + 1
Loop

End Sub 

Have fun.

---- Andy

There is a great need for a sarcasm font.

RE: Applying ID numbers to multiple rows

Hi,

Here's a solution that assumes that the Member number cell could be anywhere...

CODE

Sub FillMembNum()
    Dim r As Range, rFROM As Range, sPREV As String
    
    If ActiveSheet.Cells(1, 1).Value = "Member number" Then
        Set rFROM = ActiveSheet.Cells(1, 1)
    Else
        Set rFROM = ActiveSheet.Cells.Find("Member number", LookIn:=xlValues).Offset(1)
    End If
    
    If Not rFROM Is Nothing Then
        For Each r In Intersect(Range(rFROM, rFROM.End(xlDown).End(xlDown).End(xlDown)), ActiveSheet.UsedRange)
            If r.Value = "" Then
                r.Value = sPREV
            Else
                sPREV = r.Value
            End If
        Next
    End If
End Sub 

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Applying ID numbers to multiple rows

(OP)
Thanks so much for your help - It's working perfectly smile

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close