+ Reply to Thread
Results 1 to 6 of 6

Inserting columns

  1. #1
    FinChase
    Guest

    Inserting columns

    I have a number of spreadsheets where I need to go through and insert two
    columns at 26 places in each spreadsheet. I'm trying to make this a little
    faster by writing a VBA macro that I can run with keystrokes. What I tried
    to do was tell it select the column that I am currently in and insert two
    columns to the right of that column. The problem I am having is that it is
    inserting the columns to the left instead of the right. I can't figure out
    why. Here's the code I've written:

    With ActiveCell
    .EntireColumn.Select
    End With
    Selection.Insert Shift:=xlToRight
    Selection.Insert Shift:=xlToRight

    Any help would be appreciated.

  2. #2
    Don Guillett
    Guest

    Re: Inserting columns

    try this but you really don't have to use the active cell.

    Sub inserttwocolums()
    x = ActiveCell.Row
    y = ActiveCell.Column
    Range(Cells(x, y), Cells(x, y + 1)).EntireColumn.Insert
    End Sub


    --
    Don Guillett
    SalesAid Software
    [email protected]
    "FinChase" <[email protected]> wrote in message
    news:[email protected]...
    >I have a number of spreadsheets where I need to go through and insert two
    > columns at 26 places in each spreadsheet. I'm trying to make this a
    > little
    > faster by writing a VBA macro that I can run with keystrokes. What I
    > tried
    > to do was tell it select the column that I am currently in and insert two
    > columns to the right of that column. The problem I am having is that it
    > is
    > inserting the columns to the left instead of the right. I can't figure
    > out
    > why. Here's the code I've written:
    >
    > With ActiveCell
    > .EntireColumn.Select
    > End With
    > Selection.Insert Shift:=xlToRight
    > Selection.Insert Shift:=xlToRight
    >
    > Any help would be appreciated.




  3. #3
    Norman Jones
    Guest

    Re: Inserting columns

    Hi Fin Chase.



    --
    ---
    Regards,
    Norman



    "FinChase" <[email protected]> wrote in message
    news:[email protected]...
    >I have a number of spreadsheets where I need to go through and insert two
    > columns at 26 places in each spreadsheet. I'm trying to make this a
    > little
    > faster by writing a VBA macro that I can run with keystrokes. What I
    > tried
    > to do was tell it select the column that I am currently in and insert two
    > columns to the right of that column. The problem I am having is that it
    > is
    > inserting the columns to the left instead of the right. I can't figure
    > out
    > why. Here's the code I've written:
    >
    > With ActiveCell
    > .EntireColumn.Select
    > End With
    > Selection.Insert Shift:=xlToRight
    > Selection.Insert Shift:=xlToRight
    >
    > Any help would be appreciated.




  4. #4
    Dave Peterson
    Guest

    Re: Inserting columns

    Either select the cell to the right either manually or via code.

    activecell.offset(0,1).resize(1,2).entirecolumn.insert

    FinChase wrote:
    >
    > I have a number of spreadsheets where I need to go through and insert two
    > columns at 26 places in each spreadsheet. I'm trying to make this a little
    > faster by writing a VBA macro that I can run with keystrokes. What I tried
    > to do was tell it select the column that I am currently in and insert two
    > columns to the right of that column. The problem I am having is that it is
    > inserting the columns to the left instead of the right. I can't figure out
    > why. Here's the code I've written:
    >
    > With ActiveCell
    > .EntireColumn.Select
    > End With
    > Selection.Insert Shift:=xlToRight
    > Selection.Insert Shift:=xlToRight
    >
    > Any help would be appreciated.


    --

    Dave Peterson

  5. #5
    Norman Jones
    Guest

    Re: Inserting columns

    Hi FinChase,

    Try:
    ActiveCell(1, 2).Resize(1, 2).EntireColumn.Insert

    If the 26 positions can be identified by a given rule, then your macro could
    be adapred to insert all the required columns on each worksheet.


    ---
    Regards,
    Norman

    "FinChase" <[email protected]> wrote in message
    news:[email protected]...
    >I have a number of spreadsheets where I need to go through and insert two
    > columns at 26 places in each spreadsheet. I'm trying to make this a
    > little
    > faster by writing a VBA macro that I can run with keystrokes. What I
    > tried
    > to do was tell it select the column that I am currently in and insert two
    > columns to the right of that column. The problem I am having is that it
    > is
    > inserting the columns to the left instead of the right. I can't figure
    > out
    > why. Here's the code I've written:
    >
    > With ActiveCell
    > .EntireColumn.Select
    > End With
    > Selection.Insert Shift:=xlToRight
    > Selection.Insert Shift:=xlToRight
    >
    > Any help would be appreciated.




  6. #6
    Registered User
    Join Date
    02-06-2006
    Posts
    4
    Is it possible to insert a column into the first row programmatically using C#. I tried using
    wsSales.Columns.EntireColumn.Insert(Excel.XlInsertShiftDirection.xlShiftToRight);

    but it does not work. I even tried using a range and then inserting a column before that range but that didn't work either. Please help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1