View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Rick Rothstein \(MVP - VB\) Rick Rothstein \(MVP - VB\) is offline
external usenet poster
 
Posts: 2,202
Default Weekday question

It seems Im having a problem with weekday function.
I have a column of data values, some of those values are DATE function
given
and then there are some others in text format (even some blanks).

Trough a macro i can identify which weekday is it, so to do an action
depending on it. Everything seems to work fine until I reach a cell with
no
data (blank), then the action stops and i get a "Type mismatch Error"

How can i avoid this?, im includig the program searching for any kindda
help

Thanx

Range("d12").Activate
i = 12
Do While i < 65

If Weekday(Cells(i, 2).Value) = vbMonday Or Weekday(Cells(i, 2).Value) =
vbTuesday Or Weekday(Cells(i, 2).Value) = vbWednesday Or Weekday(Cells(i,
2).Value) = vbThursday Or Weekday(Cells(i, 2).Value) = vbFriday Then

ActiveCell.Value = cxdce
i = i + 1
ActiveCell.Offset(1, 0).Activate

Else

i = i + 1
ActiveCell.Offset(1, 0).Activate
End If
Loop


Unless I misread something, the above code can be reduced to this...

Range("d12").Activate
i = 12
Do While i < 65
If Weekday(Cells(i, 2).Value, vbMonday) < 6 Then
ActiveCell.Value = cxdce
End If
i = i + 1
ActiveCell.Offset(1, 0).Activate
Loop

Now, to solve the blank cell problem, this should work...

Range("d12").Activate
i = 12
Do While i < 65
If Trim$(Cells(i,2).Value) < "" Then
If Weekday(Cells(i, 2).Value, vbMonday) < 6 Then
ActiveCell.Value = cxdce
End If
i = i + 1
ActiveCell.Offset(1, 0).Activate
End If
Loop

Rick