Naturally at first you should check type of control, then my sample code
looks like this:
Dim cbCtl As Control
For Each cbCtl In UserForm1.Controls
If Typename(cbCtl)="Combobox" then
For i = 2 To 2 + totalwaferspre
fieldnamepre.AddItem Worksheets("Pre_Rawdata").Range("H" & i).Value
Next
End if
Next
HTH
MaC
Użytkownik "MaC" <oiram76@poczta.onetDOTpl> napisał w wiadomości
news:449d9bec@news.home.net.pl...
> It might be more useful to replace your looping thru comboboxes with
> for..each syntax
> e.g.
>
> Dim cbCtl As Control
> For Each cbCtl In UserForm1.Controls
> For i = 2 To 2 + totalwaferspre
> fieldnamepre.AddItem Worksheets("Pre_Rawdata").Range("H" & i).Value
> Next
> Next
>
> MaC
>
>
> Użytkownik "lif" <lif.29x8jz_1151177403.4221@excelforum-nospam.com>
> napisał w wiadomości
> news:lif.29x8jz_1151177403.4221@excelforum-nospam.com...
>>
>> 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
>>
>>
>> --
>> lif
>> ------------------------------------------------------------------------
>> lif's Profile:
>> http://www.excelforum.com/member.php...o&userid=35745
>> View this thread:
>> http://www.excelforum.com/showthread...hreadid=555267
>>
>
>
Bookmarks