ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Cell Insertion (https://www.excelbanter.com/excel-programming/388569-cell-insertion.html)

Matthew Wieder[_3_]

Cell Insertion
 
I am trying to automate the following, seemingly simple task, but am having
trouble doing so:
I have a range, let's say 4x4. I need to increase that range, by adding
cells on the right and below, let's say to end up with 7 x 6. I DO NOT want
to insert whole columns and rows - I only want to insert as many cells as run
the length of my initial range. Calling Range.Insert seems to insert a whole
4x4 range. Is there any way to specify teh size of what is to be inserted,
or am I stuck inserting the size of whatever is selected right at the
location it is selected?

JE McGimpsey

Cell Insertion
 
One way:

Const nADDROWS As Long = 3
Const nADDCOLS As Long = 2

With Selection
.Cells(1).Offset(.Rows.Count, 0).Resize( _
nADDROWS, .Columns.Count).Insert _
Shift:=xlShiftDown, _
CopyOrigin:=xlFormatFromLeftOrAbove
.Cells(1).Offset(0, .Columns.Count).Resize( _
.Rows.Count + nADDROWS, nADDCOLS).Insert _
Shift:=xlShiftToRight, _
CopyOrigin:=xlFormatFromLeftOrAbove
End With


In article ,
Matthew Wieder wrote:

I am trying to automate the following, seemingly simple task, but am having
trouble doing so:
I have a range, let's say 4x4. I need to increase that range, by adding
cells on the right and below, let's say to end up with 7 x 6. I DO NOT want
to insert whole columns and rows - I only want to insert as many cells as run
the length of my initial range. Calling Range.Insert seems to insert a whole
4x4 range. Is there any way to specify teh size of what is to be inserted,
or am I stuck inserting the size of whatever is selected right at the
location it is selected?



All times are GMT +1. The time now is 12:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com