A simple macro:
1.Run macro: Add a column after A (I have data at column B)
-->Now column A:same, Column B: new blank, column C:previous column B
2.Run macro again: Add a column after B
...
3.Run macro again: Add a column after C
...
A simple macro:
1.Run macro: Add a column after A (I have data at column B)
-->Now column A:same, Column B: new blank, column C:previous column B
2.Run macro again: Add a column after B
...
3.Run macro again: Add a column after C
...
Last edited by mariosmk555; 05-04-2014 at 06:31 AM.
Hi, mariosmk555,
maybe like this:
or![]()
Sub EF1008505() Cells(1, Columns.Count).End(xlToLeft).EntireColumn.Insert 'adjust the row number to match data End Sub
Ciao,![]()
Sub EF1008505_2() With ActiveSheet.UsedRange .Cells(.Cells.Count).EntireColumn.Insert End With End Sub
Holger
Use Code-Tags for showing your code: [code] Your Code here [/code]
Please mark your question Solved if there has been offered a solution that works fine for you
Hi, mariosmk555,
no need for a full quote here according to Forum Rule#12.
Only if Data exceeds Column C it would be of use here:
Starting at a certain range will not insert new columns prior to any filled cells, that´s a different requirement.![]()
Sub EF1008505_3() Dim lngIns As Long lngIns = Cells(1, Columns.Count).End(xlToLeft).Column If lngIns < 3 Then lngIns = 3 Cells(1, lngIns).EntireColumn.Insert 'adjust the row number to match data End Sub
Ciao,
Holger
Thanks for the fast response,
maybe I didn't explain well my goal.
I want to set a column: for example D (D and E are filled with data)
I want to run macro: and create 2 columns after D and shift E two times right.
When I run again the macro I want the new columns to be created after the previous two columns that macro created.
etc..
**Today is my first day with VBA and excel macro!
Hi, mariosmk555,
you should be more precise in what you are asking. In the opening post it was one column (the last one) which should be shifted. Now it´s two columns, and I´m not so sure about the columns you have used or the range where to insert:
![]()
Sub EF1008505_4() 'insert two columns before the last two columns of data Dim lngIns As Long lngIns = Cells(1, Columns.Count).End(xlToLeft).Column - 1 If lngIns < 3 Then lngIns = 3 Cells(1, lngIns).Resize(1, 2).EntireColumn.Insert End Sub
Ciao,![]()
Sub EF1008505_5() 'will start at Column C and add two columns when the workbook isn´t closed in the meantime 'If you wan to keep the value for the next opening you could write it to a cell on a hidden sheet, 'use a Name to store it or store the value in a textfile. Static lngIns As Long If lngIns = 0 Then lngIns = 3 Else lngIns = lngIns + 2 End If Cells(1, lngIns).Resize(1, 2).EntireColumn.Insert End Sub
Holger
You may try this code also.....
The code will ask you to input the column of interest, so you need to input the column alphabet. Suppose you want to insert two column after the col. D, in that case you need to input either d or D in the input box.
![]()
Sub InsertColumn() Dim c As String 'You need to input the column alphabet like d,e,f,g...etc c = InputBox("After which column you want to insert new column?") Cells(1, c).Offset(0, 1).EntireColumn.Insert Cells(1, c).Offset(0, 1).EntireColumn.Insert End Sub
Regards
sktneer
Treat people the way you want to be treated. Talk to people the way you want to be talked to.
Respect is earned NOT given.
Good idea but instead of giving the option to the user to choose the column,
(I repeat what I said above), if we give a name to the column from which the new columns will always be created before it will be easier. Can we do that in macro?
paint.jpg
Last edited by mariosmk555; 05-04-2014 at 08:55 AM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks