i have this format 08:4516:45 where both the time in and time out of an employee is inside a cell (no space) . I want to split them using column to text where only 08:45 is seen. And since i dont really know how vba works, i always use record macro that gave me the code below.
The problem is, it's so long because i have to do it on 31 columns (starting with column D and ends with column AH). It also takes time to run.
Can someone please help me how to shorten this code using loop?
The problem is, it's so long because i have to do it on 31 columns (starting with column D and ends with column AH). It also takes time to run.
Can someone please help me how to shorten this code using loop?
Code:
Columns("D:D").Select
Selection.TextToColumns Destination:=Range("D1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("E:E").Select
Selection.TextToColumns Destination:=Range("E1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("F:F").Select
Selection.TextToColumns Destination:=Range("F1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("G:G").Select
Selection.TextToColumns Destination:=Range("G1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("H:H").Select
Selection.TextToColumns Destination:=Range("H1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("I:I").Select
Selection.TextToColumns Destination:=Range("I1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("J:J").Select
Selection.TextToColumns Destination:=Range("J1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("K:K").Select
Selection.TextToColumns Destination:=Range("K1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("L:L").Select
Selection.TextToColumns Destination:=Range("L1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("M:M").Select
Selection.TextToColumns Destination:=Range("M1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("N:N").Select
Selection.TextToColumns Destination:=Range("N1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("O:O").Select
Selection.TextToColumns Destination:=Range("O1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("P:P").Select
Selection.TextToColumns Destination:=Range("P1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("Q:Q").Select
Selection.TextToColumns Destination:=Range("Q1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("R:R").Select
Selection.TextToColumns Destination:=Range("R1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("S:S").Select
Selection.TextToColumns Destination:=Range("S1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("T:T").Select
Selection.TextToColumns Destination:=Range("T1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("U:U").Select
Selection.TextToColumns Destination:=Range("U1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("V:V").Select
Selection.TextToColumns Destination:=Range("V1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("W:W").Select
Selection.TextToColumns Destination:=Range("W1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("X:X").Select
Selection.TextToColumns Destination:=Range("X1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("Y:Y").Select
Selection.TextToColumns Destination:=Range("Y1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("Z:Z").Select
Selection.TextToColumns Destination:=Range("Z1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("AA:AA").Select
Selection.TextToColumns Destination:=Range("AA1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("AB:AB").Select
Selection.TextToColumns Destination:=Range("AB1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("AC:AC").Select
Selection.TextToColumns Destination:=Range("AC1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("AD:AD").Select
Selection.TextToColumns Destination:=Range("AD1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("AE:AE").Select
Selection.TextToColumns Destination:=Range("AE1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("AF:AF").Select
Selection.TextToColumns Destination:=Range("AF1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("AG:AG").Select
Selection.TextToColumns Destination:=Range("AG1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True
Columns("AH:AH").Select
Selection.TextToColumns Destination:=Range("AH1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(5, 9)), TrailingMinusNumbers:=True