excel - Apply one macro to another sheet/workbook regardless of sheet or workbook name -


i have issue macros returning errors, , wondering if guys shed light on issue.

the macro have looks following:

sub pivot1_macro() ' ' pivot1_macro macro ' ' keyboard shortcut: ctrl+shift+m ' sheets.add activeworkbook.pivotcaches.create(sourcetype:=xldatabase, sourcedata:= _     "7-14 week!r1c2:r199c35", version:=xlpivottableversion15).createpivottable _     tabledestination:="sheet5!r3c1", tablename:="pivottable3", defaultversion _     :=xlpivottableversion15 sheets("sheet5").select cells(3, 1).select activesheet.pivottables("pivottable3").pivotfields("partmod")     .orientation = xlcolumnfield     .position = 1 end with activesheet.pivottables("pivottable3").pivotfields("enteredshift")     .orientation = xlrowfield     .position = 1 end with activesheet.pivottables("pivottable3").pivotfields("defect")     .orientation = xlrowfield     .position = 1 end activesheet.pivottables("pivottable3").adddatafield activesheet.pivottables( _     "pivottable3").pivotfields("defect quantity"), "sum of defect quantity", xlsum columns("d:d").entirecolumn.autofit columns("a:a").entirecolumn.autofit columns("b:b").entirecolumn.autofit columns("c:c").entirecolumn.autofit columns("d:d").entirecolumn.autofit range("b3").select range("b3").select end sub 

i'd apply macro active worksheet, i'm not quite sure how make set 'sourcedata' current active worksheet.

you can use '&' concatenate strings, wouldn't

sourcedata := activesheet.name & "!r1c2:r199c35" 

work current sheet's name?


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -