Loop through textboxes to find empty then add text

Pinkster69

New Member
Joined
Jun 19, 2012
Messages
48
I have a combobox with a list of Extra work Descriptions called "ExtrasComboBox" that allows the user to choose a list of Extra work which is on a Userform called "ExtrasUserForm". I have created a command button called "SaveCommandButton" that on "click" triggers the event! I also have another Userform called "EnterDetailsUserForm" were i have at least 20 textboxes in a Frame called "EnterDetailsExtrasListFrame".

Please Note: The "ExtrasUserForm" is activated by a commandButton on the "EnterDetailsUserForm"

What I am trying to achieve is to figure out how to add the combobox values from the "ExtrasUserForm" to the next empty textbox on the "EnterDetailsUserForm"

I got it to work with the code shown below but my problem is that the code populates all of the 20 Textboxes on the "EnterDetailsUserForm" instead of the first empty TextBox and when I run the code again it re writes all the 20 textBoxes with the New Value rather that the Next empty textbox.


Hope someone can help me out on this?


Code:
Private Sub SaveCommandButton_Click()

Dim ctl As Control
Dim addWorkDiscription As String

addWorkDiscription = ExtrasComboBox.Value
 
'Loop through all controls on form
  For Each ctl In EnterDetailsUserForm.EnterDetailsExtrasListFrame.Controls
    
    If ctl.Text = vbNullString And ctl.Tag <> vbNullString Then
        If Not IsNull(ctl.Value) Then
          ctl.Value = addWorkDiscription
         
        End If
        
    End If
  Next ctl
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,216,071
Messages
6,128,619
Members
449,460
Latest member
jgharbawi

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