Quick Looping userform Question

braindiesel

Well-known Member
Joined
Mar 16, 2009
Messages
571
Office Version
  1. 365
  2. 2019
  3. 2010
Platform
  1. Windows
I have a userform with 15 textboxes
If the textbox has a value then I want to run some code (newrowformulas) and then as a last step I want to put the value of the textbox in a cell.

Without knowing better, I will just repeat the code 15 times to check each box

If TextBox1.Value <> "" Then
NewRowFormulas
ActiveCell.Value = TextBox1.Value
End If
If TextBox2.Value <> "" Then
NewRowFormulas
ActiveCell.Value = TextBox2.Value
End If
etc


I suspect that there is a much easier way.

If you can help, I would appreciate it
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi braindiesel,

Yes, you can use a loop as follows.

Code:
    Dim i As Long
    For i = 1 To 15
        If Me.Controls("TextBox" & i).Value = "" Then
            NewRowFormulas
            ActiveCell.Value = Me.Controls("TextBox" & i).Value
        End If
    Next
 
Upvote 0

Forum statistics

Threads
1,214,625
Messages
6,120,598
Members
448,973
Latest member
ksonnia

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