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
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 | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
C | D | E | F | G | H | I | J | K | L | M | |||
26 | Assign Industry | ||||||||||||
27 | |||||||||||||
28 | Issuer | Industry | Coupon | Notional | Callable | Maturity | Annual Interest | Industry List | |||||
29 | AMZN | 6.75 | 2500000 | No | 2023 | 168,750.00 | AMZN | Internet | |||||
30 | DELL | 5 | 3000000 | Yes | 2024 | 150,000.00 | DELL | Hardware | |||||
31 | Ford | 6 | 1000000 | Yes | 2024 | 60,000.00 | Ford | Auto | |||||
32 | GM | 6.25 | 3000000 | No | 2029 | 187,500.00 | GM | Auto | |||||
33 | GOOGL | 6.75 | 2500000 | Yes | 2023 | 168,750.00 | GOOGL | Internet | |||||
34 | HWP | 7 | 3500000 | Yes | 2025 | 245,000.00 | HWP | Hardware | |||||
35 | INTC | 6 | 1500000 | No | 2026 | 90,000.00 | INTC | Semiconductors | |||||
36 | MSFT | 6.5 | 2000000 | No | 2026 | 130,000.00 | MSFT | Software | |||||
37 | NVDA | 7.25 | 2000000 | Yes | 2029 | 145,000.00 | NVDA | Semiconductors | |||||
38 | TSLA | 7 | 4000000 | Yes | 2025 | 280,000.00 | TSLA | Auto | |||||
Sheet2 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
I29:I38 | I29 | =E29*F29* 0.01 |