+ Reply to Thread
Results 1 to 6 of 6

Insert a column every X columns

  1. #1
    Registered User
    Join Date
    11-25-2009
    Location
    San Fransisco
    MS-Off Ver
    Excel 2007
    Posts
    4

    Smile Insert a column every X columns

    Hi everybody,

    I am looking for a VBA code (or alternatively a way of doing this in normal Excel) that can let me insert a column every X columns (for example every six columns).

    Ideally I would want a code that can let me insert a specific column (the same) every X columns, but a formula that inserts a blank column every X columns will hopefully do.

    Thanks in advance for taking time out of your day to help me out!

    -ExCeline
    Last edited by ExCeline; 11-25-2009 at 02:27 PM. Reason: Problem solved

  2. #2
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: Insert a column every X columns

    a simple interactive approach
    Please Login or Register  to view this content.
    Last edited by rwgrietveld; 11-25-2009 at 10:29 AM.
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  3. #3
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Insert a column every X columns

    sort approach
    in a spare row
    number columns 1 thro end say 1 to 40 wher 40 is your last column with data so say you want to insert at every 5th column
    in col 41 put =5*(columns($a$1:a1)+0.5 and drag across
    copy that whole row paste special values
    now select your data choose sort /options left to right chose the row you have the numbers in and sort by that
    columns will be sorted 1 ,2 ,3 ,4 ,4.5 ,5 ,6 ,7 ,8 ,8.5......... ie all the x.5 will be empty columns
    then delete spare row.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  4. #4
    Registered User
    Join Date
    11-25-2009
    Location
    San Fransisco
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Insert a column every X columns

    Thanks for the swift replies, guys!

    I've tried both methods, but unfortunately not quite managed to solve the problem yet. As far as I can tell, the VBA-formula inserts a row every other row. I can live with the fact that it pertains to rows and not colums by transposing the data. However, I am still not able to make it insert a row every x rows, only every second one.

    As for the simple sorting approach, it seems very promising. However, I am not able to get the 1, 2, 3, 4, 5, 5.5, 6, 7, 8, 9, 10, 10.5, 11 row through the formula you provided, Martin. As far as I can tell, =5*(columns($a$1:a1)+0.5) turns into 5.5, 10.5, 15.5, 20.5 etc.

    I'm sorry to ask you guys for a clarification on what is undoubtedly pretty basic stuff. I've really tried my best to make the formulas work, and will continue to do so, but any pointers you can give would be greatly appreciated!

    -ExCeline

  5. #5
    Registered User
    Join Date
    11-25-2009
    Location
    San Fransisco
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Insert a column every X columns

    Ok, I feel kinda silly asking the question and solving it myself right afterwards. I managed to put a new variable into the formula that controlled jumps and thus got a nice blank row every X rows.

    The only issue remaining is how I paste the same values in all the empty rows without pasting over the cells in my other rows. If anyone has a tip, I wouldn't mind hearing it

    -ExCeline

  6. #6
    Registered User
    Join Date
    11-25-2009
    Location
    San Fransisco
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Insert a column every X columns

    Turns out I found a kind of ad hoc way of solving my final problem as well. Thanks again for the help, guys! You really put me on the right track.

    -ExCeline

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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