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

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
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
 
Upvote 0

Forum statistics

Threads
1,214,516
Messages
6,119,978
Members
448,934
Latest member
audette89

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