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.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
How are you populating the textboxes?
 
Upvote 0
Then try this.
Code:
If Range("A1").Value <> "" Then
    UserForm1.TextBox1.Value = Range("A1").Value
End If
 
Upvote 0
Then try this.
Code:
If Range("A1").Value <> "" Then
    UserForm1.TextBox1.Value = Range("A1").Value
End If

Thank you very much but is there a way to loop through each textbox and apply the same criteria? Or do i have to repeat this for each textbox?

I was thinking if there is a way to apply the code within the userform where if a textbox is 0, then it should be blank
 
Upvote 0
If they were consistently named then it would be straightforward to loop through them but if the names are random the only real way to do it would be to put all the textbox names in a loop and go through that.
Code:
Dim arrTextBoxes As Variant
Dim I As Long

    arrTextBoxes = Array("Channel1", "CCTV2", "Driving23")

    For I = LBound(arrTextBoxes) To UBound(arrTextBoxes)
        If Range("A" & I).Value <> "" Then
            UserForm1.Controls(arrTextBoxes(I).Value = Range("A" & I).Value
        End If
    Next I
Note also, that this would only really work if it's possible to refer to the cells to populate the textboxes with some sort of pattern.
 
Upvote 0
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.
 
Upvote 0
If they were consistently named then it would be straightforward to loop through them but if the names are random the only real way to do it would be to put all the textbox names in a loop and go through that.
Code:
Dim arrTextBoxes As Variant
Dim I As Long

    arrTextBoxes = Array("Channel1", "CCTV2", "Driving23")

    For I = LBound(arrTextBoxes) To UBound(arrTextBoxes)
        If Range("A" & I).Value <> "" Then
            UserForm1.Controls(arrTextBoxes(I).Value = Range("A" & I).Value
        End If
    Next I
Note also, that this would only really work if it's possible to refer to the cells to populate the textboxes with some sort of pattern.

Thanks again but this won’t help either,

Every textbox gets populated from various cells, not just A1.

I just thought textboxes would have an option where you simply blank out 0’s, just like in worksheet where you can hide 0’s.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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