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
 

Some videos you may like

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,825
Office Version
  1. 365
Platform
  1. Windows
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
 

rmac1954

New Member
Joined
Sep 28, 2017
Messages
9
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,825
Office Version
  1. 365
Platform
  1. Windows
Glad to help & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,122,319
Messages
5,595,465
Members
413,992
Latest member
CSEGUIN1973

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