Don’t show zeroes in textboxes VBA userform

Celticfc

Board Regular
Joined
Feb 28, 2016
Messages
153
Hi,

My userform has 36 textboxes that loads values from cells.

Is there a code where if any of the textboxes is 0, it should be blank and not show 0.

It’s because when half the textboxes are 0, it looks like a mine field etc.

Thank you.
 
Why would one populate a TextBox and then undo it?
I thought that something like Norie suggested in Post 4 would be the way to go. 1 time instead of twice.

My textboxes get populated from the worksheet. On average, only 20% are 0 but they show 0’s instead of blanks. I just don’t want to see 0’s in my textboxes - I need something similar to worksheet where you can hide 0’s from view.
 
Upvote 0

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
How about...

Code:
Dim cCont As Control
For Each cCont In Me.Controls
    If TypeName(cCont) = "TextBox" And cCont.Value = 0 Then cCont.Value = ""
Next
 
Upvote 0
Same as Yongle but I had it ready. Would be a shame to let it go to waste!
Code:
Private Sub CommandButton1_Click()
Dim ctrl As Control
For Each ctrl In Me.Controls
    If TypeName(ctrl) = "TextBox" Then
        If ctrl.Value = 0 Then
            ctrl.Value = ""
        End If
    End If
Next ctrl
End Sub
 
Upvote 0
How about...

Code:
Dim cCont As Control
For Each cCont In Me.Controls
    If TypeName(cCont) = "TextBox" And cCont.Value = 0 Then cCont.Value = ""
Next

Thanks! Worked well (applied to activate event). How can I apply this code to every single userform that I have, can a public code do this?
 
Upvote 0
Worked well (applied to activate event). How can I apply this code to every single userform that I have

Goes in Standard module
Code:
Sub [B]ClearZeros[/B](UF As UserForm)
    Dim cCont As Control
    For Each cCont In UF.Controls
        If TypeName(cCont) = "TextBox" And cCont.Value = 0 Then cCont.Value = ""
    Next
End Sub

And call it like this from your UserForm Code
Code:
Private Sub UserForm_[COLOR=#ff0000]Activate[/COLOR]()

   [I][COLOR=#000080]rest of your code.......
[/COLOR][/I]
   Call [B]ClearZeros[/B](Me)

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,259
Members
452,626
Latest member
huntinghunter

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