Anthropologista
New Member
- Joined
- Nov 5, 2017
- Messages
- 12
I have a bit of a mess here. Still learning VBA, so rather than continuing to flounder, I decided to post my code thusfar.
By clicking a button on a different sheet, I need to find the cell in Col A of sheet “2018” with value “after last entry”. Upon finding that cell, I’d like to insert a number of rows (specified by user via input box) above it. Here is what I have:
Thanks for your help and suggestions.
By clicking a button on a different sheet, I need to find the cell in Col A of sheet “2018” with value “after last entry”. Upon finding that cell, I’d like to insert a number of rows (specified by user via input box) above it. Here is what I have:
Code:
Sub InsertRowsBox()
Dim endlist As Integer
Dim j As Long
Dim r As Range
myVal = "after last entry"
j = InputBox("Enter number of rows to be inserted:")
'Sheets("2018").Range("A3").Select
endlist = Sheets("2018").Cells(Rows.Count, "A").End(xlUp).Row
For Each Cell In Range("A3:A" & endlist)
If Cell.Value = myVal Then
If endlist = "" Then
endlist = endlist & Cell.Row
Else
endlist = endlist & ", " & Cell.Row
End If
End If
Next Cell
r = Range(myVal)
Range(r.Offset(0, 0), r.Offset(j, 0)).EntireRow.Insert
End Sub
Thanks for your help and suggestions.