I have to import text files to excel. These text files are huge and the data are in rows which I have to transpose to columns for which I have a simple code as given below.
Sub extraction()
Set tr = Selection
j = 2
For i = 1 To tr.Rows.Count
If Left(tr.Cells(i, 1), 6) = "(DATE)" Then
j = j + 1
Cells(j, 5) = Mid(tr.Cells(i, 1), 7, Len(tr.Cells(i, 1)))
ElseIf Left(tr.Cells(i, 1), 20) = "(SEA/WIND DIRECTION)" Then
Cells(j, 6) = Mid(tr.Cells(i, 1), 21, Len(tr.Cells(i, 1)))
ElseIf Left(tr.Cells(i, 1), 16) = "(SEA/WIND POWER)" Then
Cells(j, 7) = Mid(tr.Cells(i, 1), 17, Len(tr.Cells(i, 1)))
ElseIf Left(tr.Cells(i, 1), 7) = "(SPEED)" Then
Cells(j, 8) = Mid(tr.Cells(i, 1), 8, Len(tr.Cells(i, 1)))
ElseIf Left(tr.Cells(i, 1), 7) = "(MILES)" Then
Cells(j, 9) = Mid(tr.Cells(i, 1), 8, Len(tr.Cells(i, 1)))
ElseIf Left(tr.Cells(i, 1), 10) = "(FUEL AUX)" Then
Cells(j, 10) = Mid(tr.Cells(i, 1), 11, Len(tr.Cells(i, 1)))
ElseIf Left(tr.Cells(i, 1), 21) = "(TOTAL STEAMING TIME)" Then
Cells(j, 11) = Mid(tr.Cells(i, 1), 22, Len(tr.Cells(i, 1)))
ElseIf Left(tr.Cells(i, 1), 5) = "(RPM)" Then
Cells(j, 12) = Mid(tr.Cells(i, 1), 6, Len(tr.Cells(i, 1)))
ElseIf Left(tr.Cells(i, 1), 6) = "(SLIP)" Then
Cells(j, 13) = Mid(tr.Cells(i, 1), 7, Len(tr.Cells(i, 1)))
ElseIf Left(tr.Cells(i, 1), 7) = "(POWER)" Then
Cells(j, 14) = Mid(tr.Cells(i, 1), 8, Len(tr.Cells(i, 1)))
ElseIf Left(tr.Cells(i, 1), 14) = "(DISPLACEMENT)" Then
Cells(j, 15) = Mid(tr.Cells(i, 1), 15, Len(tr.Cells(i, 1)))
ElseIf Left(tr.Cells(i, 1), 13) = "(FUEL M/E HS)" Then
Cells(j, 16) = Mid(tr.Cells(i, 1), 14, Len(tr.Cells(i, 1)))
ElseIf Left(tr.Cells(i, 1), 13) = "(FUEL M/E LS)" Then
Cells(j, 17) = Mid(tr.Cells(i, 1), 14, Len(tr.Cells(i, 1)))
ElseIf Left(tr.Cells(i, 1), 9) = "(OIL CYL)" Then
Cells(j, 18) = Mid(tr.Cells(i, 1), 10, Len(tr.Cells(i, 1)))
ElseIf Left(tr.Cells(i, 1), 15) = "(STEAMING TIME)" Then
Cells(j, 19) = Mid(tr.Cells(i, 1), 16, Len(tr.Cells(i, 1)))
ElseIf Left(tr.Cells(i, 1), 22) = "(STEAMING TIME M/E HS)" Then
Cells(j, 20) = Mid(tr.Cells(i, 1), 23, Len(tr.Cells(i, 1)))
ElseIf Left(tr.Cells(i, 1), 22) = "(STEAMING TIME M/E LS)" Then
Cells(j, 21) = Mid(tr.Cells(i, 1), 23, Len(tr.Cells(i, 1)))
ElseIf Left(tr.Cells(i, 1), 10) = "(FUEL M/E)" Then
Cells(j, 22) = Mid(tr.Cells(i, 1), 11, Len(tr.Cells(i, 1)))
ElseIf Left(tr.Cells(i, 1), 11) = "(ECO SPEED)" Then
Cells(j, 23) = Mid(tr.Cells(i, 1), 12, Len(tr.Cells(i, 1)))
ElseIf Left(tr.Cells(i, 1), 11) = "(MILES ECO)" Then
Cells(j, 24) = Mid(tr.Cells(i, 1), 12, Len(tr.Cells(i, 1)))
ElseIf Left(tr.Cells(i, 1), 8) = "(BHP KW)" Then
Cells(j, 25) = Mid(tr.Cells(i, 1), 9, Len(tr.Cells(i, 1)))
ElseIf Left(tr.Cells(i, 1), 10) = "(SEA/WIND)" Then
Cells(j, 6) = Mid(tr.Cells(i, 1), 11, Len(tr.Cells(i, 1)))
ElseIf Left(tr.Cells(i, 1), 16) = "(SEA WIND POWER)" Then
Cells(j, 7) = Mid(tr.Cells(i, 1), 17, Len(tr.Cells(i, 1)))
End If
Next i
End Sub
Now, the problem is, in the SEA/WIND POWER column, there are data like 3/2 which when importing automatically gets converted to the date format (02-Mar).
What I want is, either the original text(say 3/2) or the greater number. Being a newbie in VBA, I just can't get to solve the issue.
Any help will be greatly appreciated. Thank you :)