Trying to take input for rows from user

siddo

Board Regular
Joined
May 26, 2020
Messages
106
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
VBA Code:
Private Sub CommandButton1_Click()

a = InputBox("Enter the Row", "Excel VBA Says", "Please enter data")
    Rows("a").Select
    Selection.Copy
    Selection.Insert Shift:=xlDown
    Range("L8").Select
    Application.CutCopyMode = False
    Selection.ClearContents
    Rows("a" + 1).Select
    Selection.Rows.Group
    ActiveSheet.Outline.ShowLevels RowLevels:=1
    
End Sub
Im getting an error at Rows("a") .Select section can someone help
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
You need to remove the quotes from around the a, so it's just Rows(a)
 
Upvote 0
Try something like:
VBA Code:
Dim a As Integer

a = Application.InputBox("Enter the Row", "Excel VBA Says", "Please enter data", Type:=1)
    Rows(a).Select
    Selection.Copy
    Selection.Insert Shift:=xlDown
    Range("L8").Select
    Application.CutCopyMode = False
    Selection.ClearContents
    Rows(a + 1).Select
    Selection.Rows.Group
    ActiveSheet.Outline.ShowLevels RowLevels:=1
 
Upvote 0
You need to remove the quotes from around the a, so it's just Rows(a)
A quick question instead of rows can I identify the rows using the S.No column I have written C1,C2 like this in my serial number column so instead of putting a row can I include C1 and C2
 
Upvote 0

Forum statistics

Threads
1,215,537
Messages
6,125,384
Members
449,221
Latest member
DFCarter

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