Results 1 to 6 of 6
  1. #1
    Lounger
    Join Date
    Aug 2013
    Posts
    45
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Set Column Headers

    Hello,

    I recorded a macro to import the text files in spreadsheet from A2. Now i want to set the column headers starting from Column A1 to Column I
    DisplayNumber, Date Ordered, Delivered, Hardware Name, Quantity, Price, Cost, Center, Standard.

    How to set this order with a macro

    Thanks in advance.

  2. #2
    WS Lounge VIP
    Join Date
    Mar 2002
    Location
    Newcazzle, UK
    Posts
    2,820
    Thanks
    133
    Thanked 481 Times in 458 Posts
    Hi

    Use this in the vba code:

    [a1] = "DisplayNumber"
    [b1] = "Date Ordered"
    [c1] = "Delivered"
    [d1] = "Hardware Name"
    [e1] = "Quantity"
    [f1] = "Price"
    [g1] = "Cost"
    [h1] = "Center"
    [i1] = "Standard"

    zeddy

  3. #3
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    371
    Thanked 1,457 Times in 1,326 Posts
    Foncesa,

    This is a just-in-case but if row 1 is not empty after the import you'll need to add the following line to the beginning of Zeddy's code.
    Code:
    [A1].EntireRow.Insert
    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  4. #4
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts
    An alternate way is the single line of code:
    [A1:I1] = Array("DisplayNumber", "Date Ordered", "Delivered", "Hardware Name", _
    "Quantity", "Price", "Cost", "Center", "Standard")

    Steve

  5. #5
    Lounger
    Join Date
    Aug 2013
    Posts
    45
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Hello,

    Thanks to all for nice suggestions.
    Thanks.

  6. #6
    WS Lounge VIP
    Join Date
    Mar 2002
    Location
    Newcazzle, UK
    Posts
    2,820
    Thanks
    133
    Thanked 481 Times in 458 Posts
    Hi foncesa

    ..and after you have imported the data and set the headings, you can adjust column widths like this:

    [di1]..ColumnWidth = 20 'sets column [D] width

    [a1:i1].Columns.Autofit 'automatically adjusts all columns in specified range to fit largest length entry in each column

    You're welcome.

    zeddy

  7. The Following User Says Thank You to zeddy For This Useful Post:

    foncesa (2014-02-15)

Posting Permissions

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