hiccup2020
New Member
- Joined
- May 28, 2020
- Messages
- 3
- Office Version
- 365
- 2019
- Platform
- Windows
I'm trying to copy elements in column B to column C if column A is blank. Please help!
Thanks!
Thanks!
ID | Work Activity |
1 | Lay out foundation |
Cement expert | |
2 | Build framework |
Builder | |
Engineer |
ID | Work Activity | Resources |
1 | Lay out foundation | Cement Expert |
2 | Build framework | Builder |
2 | Build framework | Engineer |
Sub MyMacro()
Dim r As Long
Application.ScreenUpdating = False
' Set intitial row value of 3
r = 3
' Put title on column C
Range("C1") = "Resources"
' Loop through column B
Do
' Exit if no more items in column B
If Cells(r, "B") = "" Then Exit Do
' Check to see if there is a value in column A
If Cells(r, "A") <> "" Then
' If there is, add one to r to move to next row
r = r + 1
Else
' Check to see if there is a value in column C in row above
If Cells(r - 1, "C") <> "" Then
' If there is, move column B entry to column C...
Cells(r, "C") = Cells(r, "B")
' ... and copy values in columns A and B from row above
Cells(r, "A") = Cells(r - 1, "A")
Cells(r, "B") = Cells(r - 1, "B")
' Move to next row
r = r + 1
Else
' If there is no value in column C in row above, move value up there...
Cells(r - 1, "C") = Cells(r, "B")
' ...and delete current row
Rows(r).Delete
End If
End If
Loop
Application.ScreenUpdating = True
MsgBox "Macro complete!"
End Sub