Hi Arien
I have altered your code and provided some comments (you should be able to compare the code below with your code to see where you went wrong):
Sub switchDate()
Dim MyDate As String 'Declare your vaiable
For Each cell In ActiveSheet.Range("B4:B100") 'Set range for your loop
If cell.Interior.ColorIndex <> xlNone Then '(first if)If the cell contains a colour do the next statment
MyDate = cell.Value 'pass the value of the cell to the variable
MyDate = Trim(MyDate) 'Remove any leading or trailing spaces from the variables value
If InStr(MyDate, " ") > 0 Then '(second if) If there are any spaces in the variables value do the next statement ie. proceed
MyDate = Mid(MyDate, InStr(MyDate, " ") + 1) 'Get anything after a space and pass it back to the variable
End If ' End of second if statement
MyDate = DateValue(MyDate) 'Convert variable value to a date
cell.Value = MyDate 'Write variables value back to the cell from the information was collected
End If ' End of first if statement
Next ' loop
End Sub
Cheers
Shaun
Bookmarks