Inserting multiple Columns.

Add-in Express™ Support Service
That's what is more important than anything else

Inserting multiple Columns.
 
Subscribe
Jason Clark




Posts: 5
Joined: 2017-07-19
Hello,

So I am kind of stuck on a particular need. I have a range say a1:85 it is cast into an Excel.Range. I need to insert a number of columns between 0 and n to the end of the range. Shifting everything to the left. the code I have written to do this is range.Columns.Insert(Excel.XlInsertShiftDirection.xlShiftToRight);; I think that is working right, still in the testing mode but I would like to not have to loop and call that over and over.

Is there a way to do something like range.Columns.Insert(<columns I want>, Excel.XlInsertShiftDirection.xlShiftToRight).

The reason I need this is I need to move the data in my file over before I resize my range to write the new data.
Posted 14 Sep, 2017 18:25:42 Top
Andrei Smolin


Add-in Express team


Posts: 14137
Joined: 2006-05-11
Hello Jason,

Calling Range("C:D").Insert(Excel.XlInsertShiftDirection.xlShiftToRight) in a VBA macro moves the specified columns to the right thus creating two empty columns. Replacing "C:D" with "C:E" creates three empty columns. If you need to move "A1:A85" to have three empty columns, select "A1:C85"; this also requires that you use EntireColumn:
Range("a1:c85").EntireColumn.Insert(Excel.XlInsertShiftDirection.xlShiftToRight).

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 18 Sep, 2017 06:21:03 Top