LBee
New Member
- Joined
- Dec 25, 2021
- Messages
- 20
- Office Version
- 365
- 2019
- Platform
- Windows
I have a small VBA script that, when I press button, checks if values in different cells are valid.
If not, it displays a messagebox telling which cell is not correct, otherwise is displays a messagebox saying "Everything looks fine"
It does work, but it checks one cell at a time - if 3 cells are wrong I have to press the button, fix first cell, press it again, fix second cell ...
What I like it to do, was to check all cells, and then display only one messagebox saying e.g. :
A1 is empty
A7 does not contain 5 digits
D2 does not contain 7 digits
Is that possible?
This is the script I'm currently using
If not, it displays a messagebox telling which cell is not correct, otherwise is displays a messagebox saying "Everything looks fine"
It does work, but it checks one cell at a time - if 3 cells are wrong I have to press the button, fix first cell, press it again, fix second cell ...
What I like it to do, was to check all cells, and then display only one messagebox saying e.g. :
A1 is empty
A7 does not contain 5 digits
D2 does not contain 7 digits
Is that possible?
This is the script I'm currently using
VBA Code:
Sub Button1_Click()
If IsEmpty(Range("A1")) = True Then
MsgBox "A1 is empty"
ElseIf IsNumeric(Range("B4")) = False Then
MsgBox "B4 is not a number"
ElseIf Len(Range("A7")) <> 5 Then
MsgBox "A7 does not contain 5 digits"
ElseIf Len(Range("D2")) <> 7 Then
MsgBox "D2 does not contain 7 digits"
Else
MsgBox "Everything looks fine "
End If
End Sub