Automatic zeros for blank Userform Textboxes

Big Lar

Well-known Member
Joined
May 19, 2002
Messages
557
My users can tab through the UserForm without entering a number. That's fine until the worksheet is populated where blank values in a cell produces some odd results.

So...I need to insure that every TextBox value is => 0. And since my users are used to tabbing through unused textboxes...

How can I make every blank Textbox equal to 0 on CommandButton click?
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
try something like this

Code:
Sub CommandButton1_click
    Dim ctrl as MSForms.Control
    for each ctrl in Me.controls
        if typeof ctrl is msforms.textbox then
            if ctrl.value="" then ctrl.value="0"
         end if
     next ctrl
end sub
 
Upvote 0
Thanks diddi...

That first bit did the trick.

I'm still struggling with the second code...;)
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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