Need to get vba code help.

dhylbert

New Member
Joined
Nov 26, 2012
Messages
22
I am looking to use a active x command button, when clicked, it will ask user how many rows they want to insert. I then want it to insert rows, and add row highlights. I also want column g to be change to formula. Here is the code I have so far. I am getting an error. Can someone help?

Private Sub CommandButton1_Click()

Dim numrow
numrow = Application.InputBox("How many rows would you like to add?", "Insert Row", , , , , , 1)
If IsNumeric(numrow) Then
For i = 1 To numrow
Call INR
Next i
End If


End Sub

and


Sub INR()

Sheets("Assessment").Range("A" & Rows.Count).End(x1Up).Select
ActiveCell.EntireRow.Insert Shift:=xlDown

Sheets("Assessment").Range("$A":"$L").Select
Selection.Borders.Weight = xlThin

Sheets("Assessment").Range("G4").Select
ActiveCell.Formula = "=IF(ISBLANK($F4),"", CONCATENATE(Priority & $L4 & , & $F4))"

End Sub
 

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
I'm thinking the error is the formula. You have to escape the double quotes, or reference them by ASCII value.

ActiveCell.Formula = "=IF(ISBLANK($F4)," & CHR(34) & CHR(34) & ", CONCATENATE(Priority & $L4 & , & $F4))"
 
Upvote 0
Is Priority a variable? if not I suspect that you want
VBA Code:
ActiveCell.Formula = "=IF(ISBLANK($F4),"""", CONCATENATE(""Priority "",$L4,"","",$F4))"
 
Upvote 0
Here is the error I am getting now

1628109916684.png
 
Upvote 0
See if this does what you want

In the Sheet module
VBA Code:
Private Sub CommandButton1_Click()
    Dim numrow As Long, i As Long
    
    numrow = Application.InputBox("How many rows would you like to add?", "Insert Row", , , , , , 1)
    
    If IsNumeric(numrow) Then
        For i = 1 To numrow
            Call INR
        Next i
    End If
End Sub

In a Standard Module
Code:
Sub INR()
    Dim LR As Long
    
    Sheets("Assessment").Activate
    'Get the last row with data in column A
    LR = Cells(Rows.Count, "A").End(xlUp).Row
    'Insert row before the last row with data in column A
    Range("A" & LR).EntireRow.Insert Shift:=xlDown
    'Put borders
    Range("$A" & LR).Resize(, 12).Borders.Weight = xlThin
    
    'Dont understand why the formula should be in G4. Please, explain.
    Range("G4").Formula = "=IF(ISBLANK($F4),"""", ""Priority "" & $L4 & "","" & $F4)"
End Sub

Hope this helps

M.
 
Upvote 0
On this line
VBA Code:
Sheets("Assessment").Range("A" & Rows.Count).End(x1Up).Select
you have x1Up, when it should be xlUP (a lower case L not the number 1)
 
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,500
Members
449,090
Latest member
RandomExceller01

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