Convert Date To Month And Year With VBA
The entered date in column C is transfered as months and years
into column A and column B.
Rows are colored differently for each month.
Our macro codes :
If Intersect(Target, [C2:C65536]) Is Nothing Then Exit Sub
Target.Offset(0, -2).Value = Format(Target, "mm")
Target.Offset(0, -1).Value = Format(Target, "yyyy")
Target1 = Target.Offset(0, -2)
If Target1 = 1 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 39
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = 2 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 36
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = 3 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 45
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = 4 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 12
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = 5 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 16
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = 6 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 17
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = 7 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 43
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = 8 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 20
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = 9 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 22
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = 10 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 33
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = 11 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 27
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = 12 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 40
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = "" Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 0
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 0
End If
Target.Offset(0, -2).Value = Format(Target, "mm")
Target.Offset(0, -1).Value = Format(Target, "yyyy")
Target1 = Target.Offset(0, -2)
If Target1 = 1 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 39
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = 2 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 36
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = 3 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 45
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = 4 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 12
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = 5 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 16
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = 6 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 17
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = 7 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 43
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = 8 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 20
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = 9 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 22
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = 10 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 33
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = 11 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 27
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = 12 Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 40
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 1
End If
If Target1 = "" Then
Range("A" & Target.Row & ":C" & Target.Row).Interior.ColorIndex = 0
Range("A" & Target.Row & ":C" & Target.Row).Borders.LineStyle = 0
End If
No comments:
Post a Comment