Error "Expected Procedure, Not Variable" with Command Buttons

Alan_CT06

New Member
Joined
Nov 6, 2023
Messages
13
Office Version
  1. 2016
Platform
  1. Windows
I have written some code and it all worked fine when I ran it from the VBA window.

I then went back and created some Command Buttons on the worksheet to run each procuedure.

Generally it has worked, but for a few of the procedures when I click the Command Button, I get the error message "Compile Error: Expected Procedure, Not Variable"

For example, one sub where this is happening is:

>>>>
Sub AssignIndustry()

Set LastRow = Cells.Find(What:="Issuer", After:=Cells.Find(What:="Assign Industry"), LookAt:=xlWhole).End(xlDown)
Set FirstIndustry = Cells.Find(What:="Industry", After:=Cells.Find(What:="Assign Industry"), LookAt:=xlWhole, SearchDirection:=xlNext, SearchOrder:=xlByRows).Offset(1)
Set Industry = Range(FirstIndustry, Cells(LastRow.Row, FirstIndustry.Column))
lbIndustryLabel = Cells.Find(What:="Industry List", After:=Cells.Find(What:="Assign Industry"), LookAt:=xlWhole).Offset(1)
Set IndustryList = Range(lbIndustryLabel, lbIndustryLabel.End(xlDown).End(xlToRight))

With Industry
.Formula = "=Vlookup(RC[-1]," & IndustryList.Address(True, True, ReferenceStyle:=R1C1) & ",2,false)"
End With

End Sub
>>>>


And the code for the button is:
>>>
Private Sub AssignIndustry_Click()

AssignIndustry

End Sub
>>

Here is the worksheet
VBA Practice.xlsm
CDEFGHIJKLM
26Assign Industry
27
28IssuerIndustryCouponNotionalCallableMaturityAnnual InterestIndustry List
29AMZN6.752500000No2023168,750.00AMZNInternet
30DELL53000000Yes2024150,000.00DELLHardware
31Ford61000000Yes202460,000.00FordAuto
32GM6.253000000No2029187,500.00GMAuto
33GOOGL6.752500000Yes2023168,750.00GOOGLInternet
34HWP73500000Yes2025245,000.00HWPHardware
35INTC61500000No202690,000.00INTCSemiconductors
36MSFT6.52000000No2026130,000.00MSFTSoftware
37NVDA7.252000000Yes2029145,000.00NVDASemiconductors
38TSLA74000000Yes2025280,000.00TSLAAuto
Sheet2
Cell Formulas
RangeFormula
I29:I38I29=E29*F29* 0.01
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
I seemed to have answered my own question.

I was naming my button with the same name as the procedure.

I tried putting btn at the begining of each button name and that fixed the problem.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,151
Messages
6,123,316
Members
449,094
Latest member
Chestertim

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