ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Please help with a Loop... (https://www.excelbanter.com/excel-programming/346185-please-help-loop.html)

mthomas[_21_]

Please help with a Loop...
 

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


--
mthomas
------------------------------------------------------------------------
mthomas's Profile: http://www.excelforum.com/member.php...o&userid=25649
View this thread: http://www.excelforum.com/showthread...hreadid=486951


Toppers

Please help with a Loop...
 
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

"mthomas" wrote:


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


--
mthomas
------------------------------------------------------------------------
mthomas's Profile: http://www.excelforum.com/member.php...o&userid=25649
View this thread: http://www.excelforum.com/showthread...hreadid=486951



mthomas[_23_]

Please help with a Loop...
 

Works great! Appreciate you taking the time. Have a great day!


--
mthomas
------------------------------------------------------------------------
mthomas's Profile: http://www.excelforum.com/member.php...o&userid=25649
View this thread: http://www.excelforum.com/showthread...hreadid=486951



All times are GMT +1. The time now is 06:50 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com