Looping userform ComboBox 1-10 with associated TextBox 1-10

rmac1954

New Member
Joined
Sep 28, 2017
Messages
9
I can loop through all 10 ComboBoxes with the following code.

Code:
Dim cmb As combobox, i As Integer
For i = 1 To 10
Set cmb = Me.Controls.Item("ComboBox" & i)

    MyPNum = cmb.Value
        Cells.Find(What:=MyPNum, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
[Code/]
When I try to add the TextBox 1-10 nothing I do works. I've tried :
Dim pqty As textbox, i As Integer




Dim pqty As textbox, i
and
Dim pqty As textbox

All but the last got errors.

Using the last Dim with:

Set pqty = Me.Controls.Item("TextBox" & i)

I get errors on the Set statement.

I use the partnumber in the comboboxes to find the row listing that part number, then want to place the quantity of the part ordered in the "Order Qty" column, then loop back for the next part number.

Rob
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
How about
Code:
    Dim i As Long
    Dim Pqty As Long
    Dim MyPNum As String

    For i = 1 To 10
        MyPNum = Me.Controls.Item("ComboBox" & i)
        Pqty = Me.Controls.Item("TextBox" & i)
        Cells.Find(What:=MyPNum, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
    Next i
 
Upvote 0
Message to Fluff,

It works! I wasn't expecting it to because it looked like something I already tried, but apparently it wasn't already tried and I can't believe that I'm finally past this roadblock.

Thank you very, very much!

RobMac
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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