VBA coding

kittybaker007

New Member
Joined
Mar 3, 2004
Messages
2
Private Sub UserForm_Initialize()
Dim i As Integer

For i = 1 To NProducts
ProductListBox.AddItem Product(i)
Next
ProductListBox.Selected(0) = True
End Sub

this is my code for one of my forms....it is telling me that Product(i) is not defined even though i have defined it in Module 1 Product() As String. What am I doing wrong
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

DRJ

MrExcel MVP
Joined
Feb 17, 2002
Messages
3,853
You have to declare it as public if you want anything outside the sub to know what you are talking about.

Like this

Dim x as integer
sub test()
codehere
end sub

This way other subs and userforms will know what x is.

If you do it like

sub test()
dim x as integer
code here
end sub

only sub test will know what x is and nothing else.

Hopefully this makes sense

Jacob
 
Learn Excel from Bill Jelen

Understanding data is crucial, and the easiest place to start is with Microsoft Excel.

Forum statistics

Threads
1,151,492
Messages
5,764,689
Members
425,230
Latest member
DzOus

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
Top