Hi, got a malfuntioning(??) VBA code.. After loading some exported text file, I want to add headers to it. Recorded inserting a row at the top, and typing the names. But after runnung the macro, the first data row is replaced by the header. What's wrong with this code?? Appreciate any help rendered..
Cheers
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.Workbooks.OpenText Filename:=strTargetStep2, Origin:=xlWindows, StartRow _
:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 2), Array(30, 9), Array _
(44, 9), Array(58, 1), Array(76, 1), Array(79, 9), Array(84, 9), Array(100, 9), Array(114, 1 _
), Array(133, 9), Array(152, 9), Array(171, 9), Array(185, 9), Array(193, 9), Array(197, 9) _
, Array(201, 1), Array(204, 9), Array(242, 1), Array(245, 9))
' Write the header
Rows("1:1").Select
Selection.Insert Shift:=xlDown
With xlApp.Range("A1")
.FormulaR1C1 = "TBA"
.Offset(0, 1).FormulaR1C1 = "TBA"
.Offset(0, 2).FormulaR1C1 = "TBA"
.Offset(0, 3).FormulaR1C1 = "TBA"
.Offset(0, 4).FormulaR1C1 = "TBA"
.Offset(0, 5).FormulaR1C1 = "TBA"
End With
Cheers
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.Workbooks.OpenText Filename:=strTargetStep2, Origin:=xlWindows, StartRow _
:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 2), Array(30, 9), Array _
(44, 9), Array(58, 1), Array(76, 1), Array(79, 9), Array(84, 9), Array(100, 9), Array(114, 1 _
), Array(133, 9), Array(152, 9), Array(171, 9), Array(185, 9), Array(193, 9), Array(197, 9) _
, Array(201, 1), Array(204, 9), Array(242, 1), Array(245, 9))
' Write the header
Rows("1:1").Select
Selection.Insert Shift:=xlDown
With xlApp.Range("A1")
.FormulaR1C1 = "TBA"
.Offset(0, 1).FormulaR1C1 = "TBA"
.Offset(0, 2).FormulaR1C1 = "TBA"
.Offset(0, 3).FormulaR1C1 = "TBA"
.Offset(0, 4).FormulaR1C1 = "TBA"
.Offset(0, 5).FormulaR1C1 = "TBA"
End With