Validate a Cell with VB excel

portucale

Board Regular
Joined
Jun 22, 2006
Messages
85
Hi,

I am looking for a VB statement which a cell can't be left blank, if is blank a warning message would be displayed and dind't let the user finnish the work, I've tried;
If IsNull(Value) Then
a = MsgBox("Please enter the reference number for this Monitoring, Thanks.")
Exit Sub
End If

but is not working, please any ideas would be very much appreciated.

Thanks,
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Use the Before_Save Event in the ThisWorkbook module
Code:
If Range("$A$1") = "" Then
      msgbox " You must enter a value in A1"
      Cancel = True
      Range("$A$1").Select
End If

lenze
 
Upvote 0
You can also use an InputBox to allow the user to fill in the cell value.
Code:
Sub EmptyCell()
    If ActiveCell.Value = "" Then
     varUserInput = InputBox("Please enter the reference number for this Monitoring", _
      "Need Ref#", "")
     If varUserInput <> "" Then ActiveCell.Value = varUserInput
    End If
End Sub
Note I used activecell, Lenze assigned cell to A1, adjust as desired.
 
Upvote 0
Hi,

Thanks to both, tried the first one but for some reason it allow to cary on and complete the execution, the (Cancel = True) for some reason gives the "OK" button, however I think I have resolved the issue I used the following statement;

Value = s1.Cells(7, 8)
If IsEmpty(Value) Then
a = MsgBox("Please enter a Reference number, Thanks.")
Range("$H$7").Select
Exit Sub
End If
I will be trying the second option also, as I am very new to the VB code.

Thanks again for the help, which is always very much appreciated.

Regs,
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,428
Members
448,961
Latest member
nzskater

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