Row Not Inserting Correctly VBA

Maslan

New Member
Joined
Mar 6, 2002
Messages
11
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
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,213,487
Messages
6,113,937
Members
448,534
Latest member
benefuexx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top