Hi,
This is my first post and I'm new to VBA. I'm trying to highlight any blank cells and display a message saying "there are incomplete fields" if any cells within a range are blank. I have created a button and managed to get the code to highlight any blank cells in yellow, I'm struggling to get the message box to only appear once, the best I've managed so far is it appears as the macro checks every cell. This is my current code:
Private Sub CommandButton1_Click()
Dim myRange As Range
Set myRange = Sheets("Model Exceptions Proforma").Range("=B5:B6,E5,H6:K16,D22:E28,J22:K28,J29,F30:K31,J35,D37:E43,J37:K43,J44,D47:E53,J47:K53,J54,D55,F58,F59,F60:K61,D62,I65:K66,D67:K70,G73:K76,D78,G77,I81:K83,D84,I87:K88,D89,I92:K93,D94,A98")
For Each myCell In myRange
If myCell.Text = "" And myCell.Interior.Color = vbWhite Then
myCell.Interior.ColorIndex = 36
MsgBox "There are incomplete fields"
Else
myCell.Interior.ColorIndex = xlNone
End If
Next
End Sub
This might confuse things further but I also have conditional formatting grey out some cells that don't require completion depending on what category is selected, I think the current code still colours those cells in yellow as they are left blank and then the conditional formatting just puts the grey over the top (so the yellow isn't visible). I would need the error message to only count blank cells that the conditional formatting doesn't grey out. Is that possible?
Thanks in advance
Sam
Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
Bookmarks