Help with some code please

G

Gareth

I am trying to use the code below to check dates in column C, D and E
against a date range in columns I and J and return "Yes" or "No" in column
N.

If C, D and E all contain dates it works fine, but there are some blank
cells and cells containing the word "Error".

Is there some way of checking whether there is a date in the cell before
getting the result?

For the cells containing "Error" I would like "Error" displayed in column N.

Thanks in advance.

Gareth

Sub CheckDateRange()
Application.ScreenUpdating = False
With Worksheets("Sheet1")
Set rng = .Range("C2:C" & Range("A" & Rows.Count).End(xlUp).Row)
For Each cell In rng
If cell.Value > cell.Offset(0, 7).Value Or cell.Offset(0, 1).Value <
cell.Offset(0, 6).Value Or _
cell.Offset(0, 2).Value < cell.Offset(0, 6).Value Then
cell.Offset(0, 11).Value = "Yes"
Else
cell.Offset(0, 11).Value = "No"
End If
Next cell
End With
Application.ScreenUpdating = True
End Sub
 
G

Gareth

Not sure how to use these function's in my code, any help gratefully
received.

Gareth
 
O

Orlando Magalhães Filho

See this:

Sub CheckDateRange()
Application.ScreenUpdating = False
With Worksheets("Sheet1")
Set rng = .Range("C2:C" & Range("A" & Rows.Count).End(xlUp).Row)
For Each cell In rng
If IsError(cell.Value) Or Not IsDate(cell.Value) Then
cell.Offset(0, 11).Value = IIf(IsError(cell.Value), "Error", "")
Else
If cell.Value > cell.Offset(0, 7).Value Or cell.Offset(0,
1).Value < cell.Offset(0, 6).Value Or _
cell.Offset(0, 2).Value < cell.Offset(0, 6).Value Then
cell.Offset(0, 11).Value = "Yes"
Else
cell.Offset(0, 11).Value = "No"
End If
End If
Next cell
End With
Application.ScreenUpdating = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top