Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By daleyman

Macro to Insert Column between Existing Columns

This is a discussion on Macro to Insert Column between Existing Columns within the Excel Questions forums, part of the Question Forums category; Thanks daleyman, that did the trick. I tried similar code with no sucess, but yours did the trick. I knew ...

  1. #1
    New Member
    Join Date
    Feb 2002
    Location
    Sackville
    Posts
    39

    Default

    Thanks daleyman, that did the trick. I tried similar code with no sucess, but yours did the trick. I knew it had to be something simple, but I kept going around the proper solution. Thanks for the help!!!

  2. #2
    New Member
    Join Date
    Feb 2002
    Location
    Sackville
    Posts
    39

    Default

    I have a DAT file that I am bring into Excel to modify. The field seperators are commas. When I have the required changes done, I want to save as text file, but need to put the commas back in (for import requirements in the next software package). I thought I had seen a tip to insert a blank column between all existing columns, but can't find it using search, and am getting frustrated trying to recreate it. Can anyone point me in the right direction to find the tip or tell me how to set the macro up?

  3. #3
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824

    Default

    Are there a set number of columns?
    How about saving as a csv file?
    Comma Seperated Values
    Tom


    [ This Message was edited by: TsTom on 2002-04-14 08:35 ]

  4. #4
    Board Regular
    Join Date
    Mar 2002
    Location
    London, UK
    Posts
    167

    Default

    recent topic over last 24 hours...

    click here !

    .. also, if you cannot adjust this code to do it for you, are you asking for just a macro to insert a blank column every other column?



    <table style="background-color:#0e54be" cellspacing="1" cellpadding="2"><td style="background-color:#ceffff;font-family:arial;color:#072c63;font-size:8pt;">***DALEY** :P**</td></table>

  5. #5
    New Member
    Join Date
    Feb 2002
    Location
    Sackville
    Posts
    39

    Default

    I tried the CSV format, but the program to import into will not accept it. The quotes for text fields are already brought over when I import the data into Excel. I have 16 columns, some of them blank, that require a comma to seperate. A macro to insert 15 columns is all that is required as I have the rest of the code set up already. Why is it that the simple things always seem to cause the most problems?


    [ This Message was edited by: Bagsy Baker on 2002-04-14 09:32 ]

  6. #6
    Board Regular
    Join Date
    Mar 2002
    Location
    London, UK
    Posts
    167

    Default

    still don't really understand the question. If its just alternate columns needing to be inserted, how about:



    Sub insert_column_every_other()
    For colx = 2 To 30 Step 2
    Columns(colx).Insert Shift:=xlToRight
    Next
    End Sub


    sorry, is this what you mean?
    rajannautiyal likes this.

    <table style="background-color:#0e54be" cellspacing="1" cellpadding="2"><td style="background-color:#ceffff;font-family:arial;color:#072c63;font-size:8pt;">***DALEY** :P**</td></table>

  7. #7
    MrExcel MVP Jay Petrulis's Avatar
    Join Date
    Mar 2002
    Location
    Chicago, IL USA
    Posts
    2,040

    Default

    On 2002-04-14 10:52, daleyman wrote:
    still don't really understand the question. If its just alternate columns needing to be inserted, how about:



    Sub insert_column_every_other()
    For colx = 2 To 30 Step 2
    Columns(colx).Insert Shift:=xlToRight
    Next
    End Sub


    sorry, is this what you mean?
    I don't know exactly what the OP wants, but I don't think your code will do eactly what *you* want here.

    If you are inserting columns and shifting to the right, it is much better to go from right to left, as the columns will not fall out of sync with your colx value. It will be very difficult to keep track of the columns/count this way.

    Sub insert_column_every_other()
    For colx = 30 To 2 Step -2
    Columns(colx).Insert Shift:=xlToRight
    Next
    End Sub

    will be better suited for this, much like when you delete rows, you work from bottom to top.

    Bye,
    Jay

  8. #8
    New Member
    Join Date
    Nov 2011
    Posts
    4

    Default Re: Macro to Insert Column between Existing Columns

    Hello,

    Do you know how i would rework this so it works across more columns? and potentially add in 3 columns instead of just one?

    thanks for the help

    chris

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
  •  


DMCA.com