0
Sub insertMultipleRows()
'code disables excel while macro runs'
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Application.ScreenUpdating = False
Dim rowcount As Integer
rowcount = Application.InputBox(Prompt:="how many rows do you want to insert" & ActiveCell.Row & "?", Type:=1)
'handle error for instances when row count may be negative or zero'
If rowcount <= 0 Then End

Rows(ActiveCell.Row & ":" & ActiveCell.Row + rowcount – 1).Insert Shift:=xlDown
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.ScreenUpdating = True

End Sub
2
  • 1
    what is the question? Commented Feb 2, 2022 at 11:59
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Feb 11, 2022 at 17:09

1 Answer 1

1

LOL. Spent ages scratching my head on this one. As I saw it there was no reason why this code wouldn't work. I copied your code into VBA and the below line should up red:

Rows(ActiveCell.Row & ":" & ActiveCell.Row + rowcount – 1).Insert Shift:=xlDown

For the life of me I couldn't see why and it didn't make any sense.

I deleted the line and manually typed it and everything worked fine! What the ....

Decided to paste the line from above under the line I typed and this is what I got:

enter image description here

Curiouser and curioser! I pasted both line into Text Comparer https://text-compare.com/ and there it was! You're using the wrong minus Character. What you're using is the ASCII 150 Character instead of the standard ASCII 45 character.

Here's the proper code:

Rows(ActiveCell.Row & ":" & ActiveCell.Row + rowcount - 1).Insert Shift:=xlDown
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.