Macro to Insert Column between Existing Columns

Bagsy Baker

New Member
Joined
Feb 17, 2002
Messages
41
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!!!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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?
 
Upvote 0
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
 
Upvote 0
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?
 
Upvote 0
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
 
Upvote 0
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?
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
Hi,

I kind of modified the code above for my purpose but I was wanting it to add 3 columns at a specific range of columns and put a name on row 1 for each column that I add. Each column that I add should be in the order of Assembly, Inspection, and Test.

Code:
[Dim wks As Worksheet
    Dim iCol As Long
    
    For Each wks In ActiveWindow.SelectedSheets
        With wks
            For iCol = .Cells.SpecialCells(xlCellTypeLastCell).Column To 2 Step -1
                .Columns(iCol).Insert
                .Columns(iCol).Insert
                .Columns(iCol).Insert
            Next iCol
        End With
    Next wks
   /CODE]

Thanks for the help.

Alison
 
Upvote 0

Forum statistics

Threads
1,213,490
Messages
6,113,957
Members
448,535
Latest member
alrossman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top