Surreybloke
Board Regular
- Joined
- Apr 1, 2010
- Messages
- 164
- Office Version
- 365
- Platform
- Windows
Hi,
I have the beginnings of some code to insert three rows below each row which has a name and ID to then populate those three new blank rows with the name and ID from above. I also have some code in the macro that should identify the end of the data (the first blank row) so that the macro knows to stop.
The bit I'm particularly unsure of is how to incorporate the loop and to tie the whole thing together into something that works.
Any help would be much appreciated. Here is the code so far:
Sub Add_lines()
'
' Add_lines Macro
' Add three extra lines and populate with Name and ID
' Find last row in column A with data
lastRow = ws.Cells(Rows.Count, "A").End(xlUp).Row
' Set range to blank cells in column B
Set Rng = ws.Range("B3:B" & lastRow).SpecialCells(xlCellTypeBlanks)
Rows("3:5").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A2:B2").Select
Selection.Copy
Range("A3:A5").Select
ActiveSheet.Paste
Range("A6").Select
End Sub
I have the beginnings of some code to insert three rows below each row which has a name and ID to then populate those three new blank rows with the name and ID from above. I also have some code in the macro that should identify the end of the data (the first blank row) so that the macro knows to stop.
The bit I'm particularly unsure of is how to incorporate the loop and to tie the whole thing together into something that works.
Any help would be much appreciated. Here is the code so far:
Sub Add_lines()
'
' Add_lines Macro
' Add three extra lines and populate with Name and ID
' Find last row in column A with data
lastRow = ws.Cells(Rows.Count, "A").End(xlUp).Row
' Set range to blank cells in column B
Set Rng = ws.Range("B3:B" & lastRow).SpecialCells(xlCellTypeBlanks)
Rows("3:5").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A2:B2").Select
Selection.Copy
Range("A3:A5").Select
ActiveSheet.Paste
Range("A6").Select
End Sub