excel - macro to copy multiple cell ranges and paste in a row on another sheet -
i recorded macro, i'm trying obtain creating code copy following range in code on each worksheet , paste in rows underneath each other on sheet "master".
i have following code:
sub macro1() ' ' macro1 macro ' ' dim rng range sheets("al-jackson hospital-fvar").select set rng = range( _ "k50:m50,k58:m58,k59:m59,k55:m55,k12:m12,k14:m14,k24:l24,k28:l28,k29:l29,k35:l35,k62:l62,k32:l32,k30:l30,k31:l31,k63:l63,k33:l33,k34:l34,k37:l37,k40:l40,k41:l41,k42:l42,k46:l46" _ ) rng.select selection.copy sheets("master").select range("b4").select range("b4").select selection.pastespecial paste:=xlpastevalues, operation:=xlnone, skipblanks _ :=false, transpose:=false activewindow.scrollworkbooktabs position:=xlfirst end sub
for example: on sheet 1, 2 ,3 copy following range on each sheet , paste values in sheet master starting in cell b1. sheet 1 data range should in b1, sheet 2 data range should in b2, , sheet 3 data range should in b3 , etc....
guys workbook has on 50 sheets
something should work you:
sub tgr() dim wb workbook dim ws worksheet dim wsdest worksheet dim rcell range dim adata() variant dim scells string dim long, j long set wb = activeworkbook set wsdest = wb.sheets("master") scells = "k50:m50,k58:m58,k59:m59,k55:m55,k12:m12,k14:m14,k24:l24,k28:l28,k29:l29,k35:l35,k62:l62,k32:l32,k30:l30,k31:l31,k63:l63,k33:l33,k34:l34,k37:l37,k40:l40,k41:l41,k42:l42,k46:l46" redim adata(1 wb.sheets.count - 1, 1 wsdest.range(scells).cells.count) = 0 each ws in wb.sheets if ws.name <> wsdest.name = + 1 j = 0 each rcell in ws.range(scells).cells j = j + 1 adata(i, j) = rcell.value next rcell end if next ws wsdest.range("b1").resize(ubound(adata, 1), ubound(adata, 2)).value = adata end sub
Comments
Post a Comment