vba if blank do nothing

uk747

Well-known Member
Joined
Jul 20, 2011
Messages
843
Office Version
  1. 365
Platform
  1. Windows
tried
Code:
If IsEmpty(Textbox1) Then
 Else
 If Textbox1.Value > 0 Then
MsgBox "****"
the message box also appears when textbox 1 is blank or i delete a value from it.

also tried
Code:
If TextBox1.Value = "" Then
Else
 If TextBox1.Value > 0 Then
MsgBox "*** "
 
 End If
 End If
All i need it when the textbox has a value greater than 0 the message appears and if it isnt greater than 0 or is blank then nothing
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
yup

Code:
Private Sub TextBox1_Change()
If TextBox1.Value > 0 Then
MsgBox "***"
End If
        
End Sub
still same when i delete the value i get message ***
 
Upvote 0
Code:
Private Sub CommandButton1_Click()

If TextBox1.Value > 0 Then
 If TextBox1 = Empty Then
 Else
 MsgBox "***"
End If

 End If
        
End Sub
 
Last edited:
Upvote 0
thanks I got same when I tried code below, only issue I have is when they enter a character/letter the message appears. It should only appear if a value greater than 0 i.e. 1, 2 3,4 etc and not a b or c

Code:
If TextBox1.Value = "" Then
    Exit Sub
    
    Else
If TextBox1.Value > 0 Then
MsgBox "***"
    End If
    End If
 
Upvote 0
I think you should specify the allow numics

I googled this
Code:
Private Sub TextBox1_Change() 

    OnlyNumbers 

End Sub
 
Upvote 0
I think you should specify the allow numics

I googled this
Rich (BB code):
Private Sub TextBox1_Change() 

    OnlyNumbers 

End Sub

thanks you also need to add code below TextBox for Numbers Only. Validating UserForm TextBox to Accept Only Numbers

Code:
[B]Private Sub OnlyNumbers()[/B]



    If TypeName(Me.ActiveControl) = "TextBox" Then

        With Me.ActiveControl

            If Not IsNumeric(.Value) And .Value <> vbNullString Then

                MsgBox "Sorry, only numbers allowed"

                .Value = vbNullString

            End If

        End With

    End If

    

[B]End Sub[/B]
 
Upvote 0

Forum statistics

Threads
1,223,317
Messages
6,171,422
Members
452,402
Latest member
siduslevis

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