Please Help with correct code

ada111

Board Regular
Joined
Feb 19, 2015
Messages
74
Hi, I am trying to create a spreadsheet for a client of ours and the point is to make it easier for them to access their information in the spreadsheet. They want a button to the right of their spreadsheet, which I have already created, but I need a code to where it automatically adds a new row when they click on this button. I did research and found a posting on here from awhile ago that was exactly what I needed I believe but I can't get it to work for my Excel spreadsheet.

This is the code I found: I need this code to be where I can click it and it adds an entire row above row number 11. Can someone help me with this??
Sub AddARow()
Dim varUserInput As Variant
varUserInput = InputBox("Enter Row Number where you want to add a row:", _
"What Row?")
If varUserInput = "" Then Exit Sub

RowNum = varUserInput
Rows(RowNum & ":" & RowNum).Insert Shift:=xlDown
Rows(RowNum - 1 & ":" & RowNum - 1).Copy Range("A" & RowNum)
Range(RowNum & ":" & RowNum).ClearContents
End Sub


Thank you!!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
You can try pointing your button to this.
It will select Row 11
Then Prompt for confirmation (you can comment that out if you want)
Finally it will insert a row shifting row 11 down.

Code:
Sub AddARow()
    
    ActiveSheet.Range("A11").EntireRow.Select
    If MsgBox("Really Insert a Row Above Row 11?", vbYesNo) = vbNo Then Exit Sub
    Selection.Insert Shift:=xlDown
        
End Sub
 
Upvote 0
I'm new to all of this. I'm just the tech writer for our company but I'm in charge of this. So I just need a code that when I click the button I created it just automatically adds a row. I had it to where when I clicked it, it added a row above but it was only when it was highlighted. It was this code I believe:
'Insert Row above active cell
Sub InsertMania()
ActiveCell.EntireRow.Insert

But I need a code that will add a row no matter what, highlighted or not. I need it to always add a row above A10....
 
Upvote 0
Point your button to this code:

Code:
Sub AddARow()

    'Add A Row Above Row 11 without prompting / Just shift rows down automatically
    ActiveSheet.Range("A11").EntireRow.Select
    Selection.Insert Shift:=xlDown
    ActiveSheet.Range("A1").Select

        
End Sub
 
Upvote 0
your code works fine, it's what it does that is the problem...
You are inserting a row, copying the data from the row above, then clearing the row you just inserted
Which row do you want cleared....the one above the inserted row ??
 
Upvote 0
What I'm doing is for a doctor's office. They want to be able to click this new entry button i've already made and have a row automatically form above A10 so they can put in the new patient's information
 
Upvote 0

Forum statistics

Threads
1,216,073
Messages
6,128,637
Members
449,461
Latest member
kokoanutt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top