Hi,
I'm new to the forum and also to excel macros - so what you'll see below is likely an ugly hack.
My question is (I hope) simple - I have a userform with many comboboxes.
each combobox is called similarly like pre1, pre2, pre3...
I would like to be able to populate each combobox with the same information refering to each combobox with a variable in a for loop.
I get a "type mismatch" error - I believe the issue is related to the fact that a combobox is an object and I am trying to use a string and integer variables to name an object - I just don't know how to go about fixing it?
Hopefully this is clear enough?
Private Sub UserForm_Initialize()
Dim i As Integer
Dim totalwaferspre As Integer
Dim averagepre As Single
Dim fieldnamepre As Object
Dim combobox As String
Dim g As Integer
totalwaferspre = Worksheets("Pre_Rawdata").Range("g2").Value
averagepre = Worksheets("Pre_Rawdata").Range("n2").Value
For g = 1 To totalwaferspre
combobox = "pre" & g
Set fieldnamepre = combobox
fieldnamepre.Clear
For i = 2 To 2 + totalwaferspre
fieldnamepre.AddItem Worksheets("Pre_Rawdata").Range("H" & i).Value
Next
Next
End Sub
Many Thanks,
Luis
Bookmarks