Please help with a Loop...

M

mthomas

I'm need some help with this project. Here's what I'm trying to
accomplish:

1. An employee name is in column A
2. An employee id number is in column B
3. Several rows between employees are blank in columns A & B.
4. When each employee is found, copy the employee id number down in
each row until the next employee is found in column A.
5. Repeat the operation until all employee id numbers are copied in the
range.

Example:
Range is dynamic. Will change from sheet to sheet.

Conditions are as follows:
If A2 = value And B2 = value Then
'Iterate down rows from A3 until <> '''
'Copy each cell in column B = B2 'This is the employee id number

Thanks in advance for all your help!!
 
G

Guest

Hi,

Try this (test data first!). There will only be one row for the last
employee - is this correct?

HTH

Sub AddEmployeeNumber()
Dim lastrow As Long, r As Long
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For r = 3 To lastrow
If Cells(r, 1) = "" Then Cells(r, 2) = Cells(r - 1, 2)
Next r
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top