Data validation and click button

Andre Pereira

New Member
Joined
Sep 3, 2018
Messages
21
Hi there guys!

Hope that you are all well.

This is my first post on MR Excel, so if i do something wrong (not accurate, inappropriate, too dumb, etc) please just let me know in order to improve myself.

My question:

I have a list of cells ex C10:L10 and C20:L20 and so on, and i need to some people fill this cells with some values (numeric only) and after they do it, they press a click button that validate the data and if something left to fill the message show something like this "empty cell I20, please fill and then validate again".

this click button must complies all data validation in this worksheet, because i'll have a bunch of list range to "check", but all with the same premises

Can you please help?
thanks in advance

André
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi André,
Welcome to MrExcel!
You may start by this code:
Rich (BB code):
Sub CheckEpmtyCells()
  Const MyRange = "C10:L10,C20:L20"
  Dim Cell As Range, Rng As Range
  Set Rng = Range(MyRange)
  For Each Cell In Rng
    If Trim(Cell.Value) = "" Then
      Cell.Select
      MsgBox "Empty cell " & Cell.Address(0, 0) & ", please fill and then validate again"
      Exit For
    End If
  Next
End Sub
or by that one:
Rich (BB code):
Sub CheckNumericCells()
  Const MyRange = "C10:L10,C20:L20"
  Dim Cell As Range, Rng As Range
  Set Rng = Range(MyRange)
  For Each Cell In Rng
    If VarType(Cell) <> vbDouble Then
      Cell.Select
      MsgBox "Cell " & Cell.Address(0, 0) & " is not numeric, please fill it correctly and then validate again"
      Exit For
    End If
  Next
End Sub
Regards
 
Last edited:
Upvote 0
Hi ZVI,

thanks a lot, the first one works like a charm :)

don't want to be a pain in the ***, but could you "merge" the two conditions in the same code?

1º rule -> Check if data inserted is numeric
2º rule -> if any cell is left unfilled
3º rule -> if rules 1 and 2 is verified then show message "everything is okay, thanks to ZVI :)"

Once again, thanks for the welcome message and for the suggested code

Regards,
André


Hi André,
Welcome to MrExcel!
You may start by this code:
Rich (BB code):
Sub CheckEpmtyCells()
  Const MyRange = "C10:L10,C20:L20"
  Dim Cell As Range, Rng As Range
  Set Rng = Range(MyRange)
  For Each Cell In Rng
    If Trim(Cell.Value) = "" Then
      Cell.Select
      MsgBox "Empty cell " & Cell.Address(0, 0) & ", please fill and then validate again"
      Exit For
    End If
  Next
End Sub
or by that one:
Rich (BB code):
Sub CheckNumericCells()
  Const MyRange = "C10:L10,C20:L20"
  Dim Cell As Range, Rng As Range
  Set Rng = Range(MyRange)
  For Each Cell In Rng
    If VarType(Cell) <> vbDouble Then
      Cell.Select
      MsgBox "Cell " & Cell.Address(0, 0) & " is not numeric, please fill it correctly and then validate again"
      Exit For
    End If
  Next
End Sub
Regards
 
Upvote 0
Below is a merged version of the code:
Rich (BB code):
Sub CheckDataCells()
  Const MyRange = "C10:L10,C20:L20"
  Dim Cell As Range, Rng As Range
  Set Rng = Range(MyRange)
  For Each Cell In Rng
    If VarType(Cell) <> vbDouble Then
      Cell.Select
      If Trim(Cell.Value) = "" Then
        MsgBox "Empty cell " _
              & Cell.Address(0, 0) _
              & ", please fill and then validate again"
      Else
        MsgBox "Cell " _
              & Cell.Address(0, 0) _
              & " is not numeric, please fill it correctly and then validate again"
      End If
      Exit Sub
    End If
  Next
  MsgBox "Everything is okay!", Title:="Well done!"
End Sub
 
Last edited:
Upvote 0
Once again, works just perfectly!!!

I want to thank you again your kindness and availability :), it's never too much :)

Kind regards mate,

André
 
Upvote 0
Pleasure to know it has helped!
(y)
 
Upvote 0

Forum statistics

Threads
1,214,946
Messages
6,122,401
Members
449,081
Latest member
JAMES KECULAH

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