• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

how to insert multiple columns before and after a single column

SANTHOSH

Member
Stop writting in ALL CAPS.
@Dear All,

I want to insert columns before and after a particular column as per attachment.

How is it possible with macro ? Any help will be appreciated.
With keyboard Control+Spacebar and Control+(numeric keypad) single column column can be inserted.


SANTHOSH
 

Attachments

  • JOB ASSIGNMENT CHART FOR BALANC SHEET 2013-14-20.3.xls
    24 KB · Views: 12
Hi Santhosh

I can't really tell from your file what columns need inserting but I suspect you want to replicate the keyboard shortcut you mention above.

To insert a row with vb something like

Code:
range("a1").entirecolumn.insert

To make that code a bit more dynamic you would do something like

Code:
selection.entirecolumn.insert

Which would put a column in where the cursor is positioned.

Hope this points you in the right direction.

Take care

Smallman
 
I do not get it. What is it that you're trying to accomplish here?
Is the 'particular column' always the same?


i.e. assuming that you want to insert a whole column before and after the column you have the active cell in, this is the way to go
Code:
Sub addcolumnsaf8andb4()
     ActiveCell.EntireColumn.Offset(0, 1).Insert
     ActiveCell.EntireColumn.Insert
End Sub
 
@Hai Smallman,

This function inserts two columns before a particular column. What I want insertion of columns before and after a column. Earlier I was doing this with some macro. But, forgot. I think the code is slightly different.

Can you help me out ?


SANTHOSH
 
Dear Santhosh

from which column (B,C,D,E), you want to insert one column before(left side) and one column after (right side). I can't able to findout. Please suggest.
 
did you give my macro a try? works like a charm, all you have to do is select a cell in the 'particular column'
 
@Hellow Vijay Kumar,

What I requested is to insert two columns before and after a single column in order to make a spacing on both sides. When I used the macro provide here, it is inserting two columns before the selected column.


SANTHOSH
 
Santhosh

I think the problem you have had is that your file is so ambiguous. You have some smart people looking at posts here and most are probably scratching their heads when looking at your file. When you post a file show what the data looks like before and after and in your case a second sheet called After with a blank column before and a blank column after and a big arrow pointing to the Active Column in the middle.

Think of the people viewing your post and how they might interpret what you are showing.

Here is my take on the additional information you have provided.

Code:
Sub AddEitherSide()
    ActiveCell.EntireColumn.Insert
    ActiveCell.Offset(, 2).EntireColumn.Insert
End Sub

Take care

Smallman
 
Back
Top