sparky2205
Well-known Member
- Joined
- Feb 6, 2013
- Messages
- 507
- Office Version
- 365
- 2016
- Platform
- Windows
Hi folks,
I'm trying to create a macro that will allow the user to input newrows in a protected worksheet based on a starting point and a number ofrows.
The newly entered rows will be copies of the row above where the new rows willbe entered. That row contains formulas which must copy with the rows.
I can get this working using ActiveCell but I don’t want the user to have to selectthe row in the worksheet before running the macro.
So what I want is to allow the user toenter the starting position and the number of rows and based on this informationperform the task.
This is where I’m at but I’m having aproblem assigning the starting position to a variable.
I think the problem is with r = "A" & s
I’m getting the “Object variable or Withblock variable not set” error.
Any help would be greatly appreciated.
I'm trying to create a macro that will allow the user to input newrows in a protected worksheet based on a starting point and a number ofrows.
The newly entered rows will be copies of the row above where the new rows willbe entered. That row contains formulas which must copy with the rows.
I can get this working using ActiveCell but I don’t want the user to have to selectthe row in the worksheet before running the macro.
So what I want is to allow the user toenter the starting position and the number of rows and based on this informationperform the task.
This is where I’m at but I’m having aproblem assigning the starting position to a variable.
Code:
Sub InsertMultipleRows()
Dim s As Variant
Dim n As Variant
Dim r As Range
'Get the starting position
s= Application.InputBox("Enter the starting position", , , , , , , 1 +2)
If s = False Then
Exit Sub
ElseIf s = "" Then
Exit Sub
End If
r= "A" & s
'Get the number of rows to input
n= Application.InputBox("Enter the number of rows to input", , , , , ,, 1 + 2)
If n = False Then
Exit Sub
ElseIf n = "" Then
Exit Sub
End If
'Unprotect the sheet
ActiveSheet.Unprotect Password:=""
'Copy the cell
r.EntireRow.Copy
'Fill down the required numbe of times
Range(r.Offset(1, 0), r.Offset(n, 0)).EntireRow.Insert Shift:=xlDown
Application.CutCopyMode = False
End Sub
I’m getting the “Object variable or Withblock variable not set” error.
Any help would be greatly appreciated.
Last edited by a moderator: