PDA

View Full Version : [SOLVED:] Insert N cells for M new rows?



JKB
10-22-2015, 01:31 AM
Hi everybody!
Im trying to insert N cells (fx 4) as a row, m (fx 5) times, i.e. i would like to insert NxM cells, where A2 is the first of them.
The reason it cannot be an entire row, is that i have a graph next to my data, and it's not so neat that when i push down cells i shift the graphs down as well. Tried google, but usualy people only insert multiple, entire rows.

Does anybody know how to do this in VBA? :)

JKB
10-22-2015, 01:49 AM
Im currently using this one, to insert N rows (in this case N = iWeather)
shtHis.Range("A2", shtHis.Cells(2, iWeather + 1)).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove

But i would like to do this M times? There must be a smarter way of doing this than a loop! :)

mancubus
10-23-2015, 01:08 AM
hi JKB

can you add a file with two sheets which display before and after macro table structure?

snb
10-23-2015, 01:32 AM
In Excel you can't 'add/insert' rows nor columns: rows.count and columns.count are fixed.
In your case I'd consider moving the graph 5 columns to the right.

JKB
10-29-2015, 12:56 AM
Okay... The problem was embarrissingly simple! You just define the range you want to insert, fx:
sht.Range("A2", sht.Cells(N, M)).Insert shift:=xlDown, copyorigin:=xlFormatFromLeftOrAbove

If somebody else ever should have this problem! ;)