Thanks Thanks:  0
Likes Likes:  0
Results 1 to 2 of 2

Thread: Row Not Inserting Correctly VBA

  1. #1
    New Member
    Join Date
    Mar 2002
    Posts
    11
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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


  2. #2
    Rest in Peace
    Join Date
    Feb 2002
    Posts
    1,582
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi Maslan

    Try

    xlApp.ActiveSheet.Rows("1:1").Insert

    xlApp.ActiveSheet.Range("A1:F1") = "TBA"




Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •