ssanguszko
03-02-2011, 10:00 AM
Hi,
I have large number like 20110202083011000 and I want to cut this one with VBA into 2 columns - one with 20110202 and second with 083011, rest of "000" will be deleted. I tried Mid function with many setting of format type "general", and "@" but still get errors like when cell format is set to text all zero at the end of 083000 (which is time), are converted to letters. Another one is a problem with the fact that when cell's format is set to numeric then I cant add 0 at the beginning. So I have either no 0 at the begining or have letter AE etc at the end when changing to text format.
Sub nowie()
Application.ScreenUpdating = False
range("A2").Activate
Columns("A:B").Insert Shift:=xlToLeft
ActiveCell.Offset(-1, 0).EntireRow.Delete
Columns("A:B").Select
Selection.NumberFormat = "General"
range("c1").Activate
ActiveCell.Value = range("c1")
Do
lancuch = ActiveCell.Value
rok = Mid(lancuch, 1, 9)
ActiveCell.Offset(0, -1).Select
ActiveCell.Value = rok
ActiveCell.Offset(0, -1).Select
ActiveCell.Value = "0W20H11"
ActiveCell.Offset(0, 2).Select
lancuch2 = ActiveCell.Value
czas = Mid(lancuch2, 11, 5)
ActiveCell.Value = "0" & czas
ActiveCell.Offset(1, 0).Select
Loop Until IsEmpty(ActiveCell.Offset(0, 1))
End Sub
I have large number like 20110202083011000 and I want to cut this one with VBA into 2 columns - one with 20110202 and second with 083011, rest of "000" will be deleted. I tried Mid function with many setting of format type "general", and "@" but still get errors like when cell format is set to text all zero at the end of 083000 (which is time), are converted to letters. Another one is a problem with the fact that when cell's format is set to numeric then I cant add 0 at the beginning. So I have either no 0 at the begining or have letter AE etc at the end when changing to text format.
Sub nowie()
Application.ScreenUpdating = False
range("A2").Activate
Columns("A:B").Insert Shift:=xlToLeft
ActiveCell.Offset(-1, 0).EntireRow.Delete
Columns("A:B").Select
Selection.NumberFormat = "General"
range("c1").Activate
ActiveCell.Value = range("c1")
Do
lancuch = ActiveCell.Value
rok = Mid(lancuch, 1, 9)
ActiveCell.Offset(0, -1).Select
ActiveCell.Value = rok
ActiveCell.Offset(0, -1).Select
ActiveCell.Value = "0W20H11"
ActiveCell.Offset(0, 2).Select
lancuch2 = ActiveCell.Value
czas = Mid(lancuch2, 11, 5)
ActiveCell.Value = "0" & czas
ActiveCell.Offset(1, 0).Select
Loop Until IsEmpty(ActiveCell.Offset(0, 1))
End Sub