![]() |
Inserting columns
I have a number of spreadsheets where I need to go through and insert two
columns at 26 places in each spreadsheet. I'm trying to make this a little faster by writing a VBA macro that I can run with keystrokes. What I tried to do was tell it select the column that I am currently in and insert two columns to the right of that column. The problem I am having is that it is inserting the columns to the left instead of the right. I can't figure out why. Here's the code I've written: With ActiveCell .EntireColumn.Select End With Selection.Insert Shift:=xlToRight Selection.Insert Shift:=xlToRight Any help would be appreciated. |
Inserting columns
try this but you really don't have to use the active cell.
Sub inserttwocolums() x = ActiveCell.Row y = ActiveCell.Column Range(Cells(x, y), Cells(x, y + 1)).EntireColumn.Insert End Sub -- Don Guillett SalesAid Software "FinChase" wrote in message ... I have a number of spreadsheets where I need to go through and insert two columns at 26 places in each spreadsheet. I'm trying to make this a little faster by writing a VBA macro that I can run with keystrokes. What I tried to do was tell it select the column that I am currently in and insert two columns to the right of that column. The problem I am having is that it is inserting the columns to the left instead of the right. I can't figure out why. Here's the code I've written: With ActiveCell .EntireColumn.Select End With Selection.Insert Shift:=xlToRight Selection.Insert Shift:=xlToRight Any help would be appreciated. |
Inserting columns
Hi Fin Chase.
-- --- Regards, Norman "FinChase" wrote in message ... I have a number of spreadsheets where I need to go through and insert two columns at 26 places in each spreadsheet. I'm trying to make this a little faster by writing a VBA macro that I can run with keystrokes. What I tried to do was tell it select the column that I am currently in and insert two columns to the right of that column. The problem I am having is that it is inserting the columns to the left instead of the right. I can't figure out why. Here's the code I've written: With ActiveCell .EntireColumn.Select End With Selection.Insert Shift:=xlToRight Selection.Insert Shift:=xlToRight Any help would be appreciated. |
Inserting columns
Either select the cell to the right either manually or via code.
activecell.offset(0,1).resize(1,2).entirecolumn.in sert FinChase wrote: I have a number of spreadsheets where I need to go through and insert two columns at 26 places in each spreadsheet. I'm trying to make this a little faster by writing a VBA macro that I can run with keystrokes. What I tried to do was tell it select the column that I am currently in and insert two columns to the right of that column. The problem I am having is that it is inserting the columns to the left instead of the right. I can't figure out why. Here's the code I've written: With ActiveCell .EntireColumn.Select End With Selection.Insert Shift:=xlToRight Selection.Insert Shift:=xlToRight Any help would be appreciated. -- Dave Peterson |
Inserting columns
Hi FinChase,
Try: ActiveCell(1, 2).Resize(1, 2).EntireColumn.Insert If the 26 positions can be identified by a given rule, then your macro could be adapred to insert all the required columns on each worksheet. --- Regards, Norman "FinChase" wrote in message ... I have a number of spreadsheets where I need to go through and insert two columns at 26 places in each spreadsheet. I'm trying to make this a little faster by writing a VBA macro that I can run with keystrokes. What I tried to do was tell it select the column that I am currently in and insert two columns to the right of that column. The problem I am having is that it is inserting the columns to the left instead of the right. I can't figure out why. Here's the code I've written: With ActiveCell .EntireColumn.Select End With Selection.Insert Shift:=xlToRight Selection.Insert Shift:=xlToRight Any help would be appreciated. |
Inserting columns
Is it possible to insert a column into the first row programmatically using C#. I tried using wsSales.Columns.EntireColumn.Insert(Excel.XlInsert ShiftDirection.xlShiftToRight); but it does not work. I even tried using a range and then inserting a column before that range but that didn't work either. Please help! -- rkappini ------------------------------------------------------------------------ rkappini's Profile: http://www.excelforum.com/member.php...o&userid=31216 View this thread: http://www.excelforum.com/showthread...hreadid=496406 |
All times are GMT +1. The time now is 08:34 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com