Datavalidation not working

nirmalachr

New Member
Joined
Nov 25, 2013
Messages
26
Hi,

The below code i had used to validate the data entered in corresponding fields but the code is not working only numeric condition is working and i had added data validation at the end of the command button before last line.

Private Sub datavalidation()


If Not IsNumeric(TextBox3.Value) Then
MsgBox "Amount Field can not be blank"
Exit Sub
End If
If TextBox2.Value = "" Then
MsgBox "Please enter the type of Proposal"
Exit Sub
End If
If TextBox1.Value = "" Then
MsgBox ("Sorry, you need to provide an Amount")
TextBox1.SetFocus
Exit Sub
End If
'If TextBox1.Value = " " Then
'MsgBox "Please enter the Applicant Name"
'Exit Sub
'End If
If ComboBox1.Value = "" Then
MsgBox "Sorry, You need to select Branch Code"
Exit Sub
End If
If ComboBox2.Value = "" Then
MsgBox "Sorry, You need to select Branch Name"
Exit Sub
End If
If ComboBox3.Value = "" Then
MsgBox "Sorry, You need to select The Proposar Status"
Exit Sub
End If
If ComboBox4.Value = "" Then
MsgBox "Sorry, You need to select Dealing Officer"
Exit Sub
End If
If ComboBox5.Value = "" Then
MsgBox "Sorry, You need to select The Disposal"
Exit Sub
End If
End Sub


Please help me if my program is worng
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
looks like it should work

it does exit on the first fail though

for example, if you wish to test the third check then you have to pass the first two

put a stop command at begining

the code will pause during execution

use F8 to step through code

pointing mouse cursor at variables (no click required) causes their value to be displayed


Code:
Private Sub datavalidation()


     Stop


     If Not IsNumeric(TextBox3.Value) Then
 
Last edited:
Upvote 0
Try syntax like below and see if it helps
Code:
If Len(TextBox1.Text) = 0 Then
     MsgBox "Sorry, you need to provide an Amount"""
     Else: MsgBox "YIPPEE"
Exit Sub
 
Upvote 0
Hi Mark,

I used the syntax which you gave it is working but sheet is updating with other values.

Can u help me out from this.
 
Upvote 0
Are you saying that if you type AAA in TextBox1 and with a command button that has the code below you don't get AAA in A1????

Code:
Private Sub CommandButton1_Click()
    If Len(TextBox1.Text) = 0 Then
        MsgBox "Sorry, you need to provide an Amount"""
    Else
        Range("A1") = TextBox1.Text
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

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