vba - Excel Macro: Inserting a column and copying the formula into it from the adjacent column -
i trying insert column sheet , copying formulas adjacent column right.
the place insert column being read work sheet itself. e.g column s (column 19).
so need insert new column @ column
"s" , copy formulas "old" column s, column t.
i using following code giving me 1004 error.
sub insert_rows_loop() dim currentsheet object 'msgbox "ghj" & sheet16.range("h2").value sheet2.cells(1, sheet16.range("h2").value).entirecolumn.select selection.copy selection.insert shift:=xltoleft application.cutcopymode = false sheet2.cells(1, sheet16.range("g2").value).entirecolumn.select selection.copy selection.insert shift:=xltoleft application.cutcopymode = false sheet2.cells(1, sheet16.range("f2").value).entirecolumn.select selection.copy selection.insert shift:=xltoleft application.cutcopymode = false end sub
the code below following:
insert new column left of current column s
set formulas in column s formulas in column t (old column s) column s
dim currentsheet worksheet set currentsheet = thisworkbook.sheets("sheet1") currentsheet 'inserting column before column s .range("s1").entirecolumn.insert 'copying formulas t(old s) s .range("s1").entirecolumn.formula = .range("t1").entirecolumn.formula end
you need adjust value in range
suit requirement , sheet
referencing different.
i hope idea behind it.
Comments
Post a Comment