Userform multi textboxes data to only specific columns

quintin

Board Regular
Joined
Jun 26, 2013
Messages
52
Good day,
I have a userform that has 20+ textboxes that you can choose from (i know how to have it enter the data to a spreadsheet over x amount of columns) however what I would like to know is if I only pick three or four textboxes (eg: glass, mug, plate - price related (so now I've used 6 textboxes) i need them to be listed down in a spreadsheet - So choosing those items it will list them down in column a and b.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
What are the names of your TextBoxes and how do those that you want to put in column A relate to those that you want to put in column B?
 
Upvote 0
What are the names of your TextBoxes and how do those that you want to put in column A relate to those that you want to put in column B?

They are named textbox1, textbox2 and etc - So textbox1 you would enter a name eg: mug and in the textbox2 next to that the price
 
Upvote 0
Try using this code in whatever event procedure (probably a button click) you are using to process the data in the TextBoxes...

Code:
  Dim Index As Long, Cntrl As Control
  For Each Cntrl In Controls
    If TypeOf Cntrl Is MSForms.TextBox Then
      If Val(Replace(Cntrl.Name, "TextBox", "")) Mod 2 Then
        Index = Val(Replace(Cntrl.Name, "TextBox", ""))
        If Len(Cntrl.Text) Then
          If Len(Controls("TextBox" & Index + 1)) Then
            Cells(Rows.Count, "A").End(xlUp).Offset(1).Resize(, 2) = Array(Cntrl.Text, Controls("TextBox" & Index + 1).Text)
          End If
        End If
      End If
    End If
  Next
 
Upvote 0
Thank you so much, I was thinking could i change it that I use comboxes in col A and textboxes in col B...Using the comboxes would save typing time...just thinking - once again thx
 
Upvote 0
Thank you so much, I was thinking could i change it that I use comboxes in col A and textboxes in col B...Using the comboxes would save typing time...just thinking - once again thx
Assuming your ComboBoxes are named ComboBox1, ComboBox2, etc. and their corresponding TextBoxes are named TextBox1, TextBox2, etc., then give this a try...
Code:
  Dim Index As Long, Cntrl As Control
  For Each Cntrl In Controls
    If TypeOf Cntrl Is MSForms.ComboBox Then
      If Cntrl.ListIndex > -1 Then
        Index = Val(Replace(Cntrl.Name, "ComboBox", ""))
        If Len(Controls("TextBox" & Index)) Then
          Cells(Rows.Count, "A").End(xlUp).Offset(1).Resize(, 2) = Array(Cntrl.Text, Controls("TextBox" & Index).Text)
        End If
      End If
    End If
  Next
 
Upvote 0
Assuming your ComboBoxes are named ComboBox1, ComboBox2, etc. and their corresponding TextBoxes are named TextBox1, TextBox2, etc., then give this a try...
Code:
  Dim Index As Long, Cntrl As Control
  For Each Cntrl In Controls
    If TypeOf Cntrl Is MSForms.ComboBox Then
      If Cntrl.ListIndex > -1 Then
        Index = Val(Replace(Cntrl.Name, "ComboBox", ""))
        If Len(Controls("TextBox" & Index)) Then
          Cells(Rows.Count, "A").End(xlUp).Offset(1).Resize(, 2) = Array(Cntrl.Text, Controls("TextBox" & Index).Text)
        End If
      End If
    End If
  Next

Hi there,
I tried the code and it came up with a message - "could not find the specified object

Code:
      If Len(Controls("TextBox" & Index)) Then
 
Upvote 0
Hi there,
I tried the code and it came up with a message - "could not find the specified object

Code:
      If Len(Controls("TextBox" & Index)) Then

Did you see where I wrote this...

"Assuming your ComboBoxes are named ComboBox1, ComboBox2, etc. and their corresponding TextBoxes are named TextBox1, TextBox2, etc"

Actually, though, the sequence of the numbers is unimportant... all that matters is that the number after the ComboBox matches the number after TextBox for the TextBox/ComboBox pairing.
 
Upvote 0
Did you see where I wrote this...

"Assuming your ComboBoxes are named ComboBox1, ComboBox2, etc. and their corresponding TextBoxes are named TextBox1, TextBox2, etc"

Actually, though, the sequence of the numbers is unimportant... all that matters is that the number after the ComboBox matches the number after TextBox for the TextBox/ComboBox pairing.

I now understand why it is not working correctly - all the comboxes and textboxes are like it should be combox1 / textbox1 however I have to extra comboxes one for clients name (cmb_name) and the other method of payment named (cmb_method)
Not sure how to over come that
and two textbox name tb_date and tb_time
 
Last edited:
Upvote 0
I now understand why it is not working correctly - all the comboxes and textboxes are like it should be combox1 / textbox1 however I have to extra comboxes one for clients name (cmb_name) and the other method of payment named (cmb_method)
Not sure how to over come that
and two textbox name tb_date and tb_time
If those extra two ComboBoxes' names do not start with "ComboBox", then I do not see what the problem would be... they will be ignored by my code... only ComboBoxes and TextBoxes with the same ending numbers are looked at.
 
Upvote 0

Forum statistics

Threads
1,216,113
Messages
6,128,905
Members
449,477
Latest member
panjongshing

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