View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Dave O Dave O is offline
external usenet poster
 
Posts: 427
Default Macro looping problem.

You could also do it this way:

Sub fillInShiftColumna()
Dim timeA1 As Date, timeA2 As Date, timeB1 As Date
Dim timeB2 As Date, timeC1 As Date, timeC2 As Date
timeB1 = TimeValue("7:00:00 AM")
timeB2 = TimeValue("14:59:59 PM")
timeA1 = TimeValue("23:00:00 PM")
timeA2 = TimeValue("6:59:59 AM")
timeC1 = TimeValue("15:00:00 PM")
timeC2 = TimeValue("22:59:59 PM")
Dim cell As Range
Range("A1:A100").Select
For Each cell In Selection.Cells
If cell.Value = timeB1 And cell.Value <= timeB2 Then
cell.Offset(0, 1).Value = "B"
ElseIf cell.Value = timeC1 And cell.Value <= timeC2 Then
cell.Offset(0, 1).Value = "C"
ElseIf cell.Value = timeA1 And cell.Value <= timeA2 Then
cell.Offset(0, 1).Value = "A"
End If
Next
Range("a1").Select
End Sub