Question : VBA Code help

I have attached my worksheet as this should help best explain.

I now have a command button that once pressed checks the format of cells B7:H29

The code appears to work fine and highlights anything in yellow when a line is not fully completed or the incorrect format.

There is just one anomaly I wish to iron out. In cell D10 I have purposely hit the space bar a few times. I would like the command button to also highlight instances of when an additional space has been used erroneously.

Many thanks for your help

Gaz  
Attachments:

Answer : VBA Code help

How about the following replacing:

        If IsDate(Cells(i, jj)) Then
with
        If IsDate(Cells(i, jj)) And InStr(Cells(i, jj), " ") = 0 Then

Chris
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
Private Sub CommandButton1_Click()

Dim i, j, jj As Integer

'Clears the existing color format
Range("B7:H29").Select
Selection.Interior.ColorIndex = xlNone

'Formats as reqd.
For i = 7 To 29
    If Application.WorksheetFunction.CountBlank(Range("B" & i & ":H" & i)) = 7 Then
    Else
    For j = 2 To 3
        If Cells(i, j) = "" Then
            Cells(i, j).Select
            Selection.Interior.ColorIndex = 6
        End If
    Next
    For jj = 4 To 8
        If IsDate(Cells(i, jj)) And InStr(Cells(i, jj), " ") = 0 Then
        Else
            Cells(i, jj).Select
            Selection.Interior.ColorIndex = 6
        End If
    Next
    End If
Next
End Sub
Random Solutions  
 
programming4us programming4us