vba - Getting My Script To Run Across All Worksheets (Excel) -
this code works on 1 sheet and trying work across multiple sheets, avoiding first 2 sheets ("aa" , "word frequency").
original code here (see @jeeped's answer)
link worksheet here
was trying adapt code related threads found (reference 1, 2) not know how (and whether) apply ws.name
, ws.range
objects existing code.
it seems code activates sheet1 using with worksheets("sheet1")
, trying replace following method:
create
for
looped function bygroupcounter() identify how many worksheets there are, , run across existing worksheets. each worksheet incremented variable "i"for
loop in bygroupcounter() calls on function bygroup(i) run original code on selected worksheet (ie. worksheet "i")the bygroup() function runs it's process across worksheet i.
part believe i'm getting error: replacing
with worksheets("sheet1")
codewith ws
,ws = worksheets(sheet_index)
, sheet_index equal i, definedbygroupcounter()
i believe have add ws
prefix in front of .range
i've been trying, keep getting error "can't execute code in break mode".
current code:
sub bygroupcounter() dim integer application.screenupdating = false = activesheet.index sheets.count bygroup next application.screenupdating = true end sub sub bygroup(byval sheets_index integer) dim g long, s long, astrs variant, agrps variant dim ws worksheet set ws = worksheets(sheet_index) apptggl btggl:=false ' believe next line doing wrong: ws astrs = .range(.cells(2, 1), .cells(rows.count, 1).end(xlup)).value2 .range(.cells(1, 5), .cells(rows.count, 1).end(xlup).offset(0, application.match("zzz", .rows(1)) - 1)) .resize(.rows.count, .columns.count).offset(1, 0).clearcontents agrps = ws.cells.value2 end s = lbound(astrs, 1) ubound(astrs, 1) g = lbound(agrps, 2) ubound(agrps, 2) if cbool(instr(1, astrs(s, 1), agrps(1, g), vbtextcompare)) agrps(s + 1, g) = astrs(s, 1) exit end if next g next s .cells(1, 5).resize(ubound(agrps, 1), ubound(agrps, 2)) = agrps end apptggl end sub public sub apptggl(optional btggl boolean = true) debug.print timer application.screenupdating = btggl application.enableevents = btggl application.displayalerts = btggl application.calculation = iif(btggl, xlcalculationautomatic, xlcalculationmanual) end sub
there 6 changes original code loop through sheets
i have them commented '<<<
sub bygroup() dim g long, s long, astrs variant, agrps variant, sh worksheet '<<< apptggl btggl:=false each sh in sheets '<<< if sh.name <> "aa" , sh.name <> "word frequency" '<<<< sh '<<< astrs = .range(.cells(2, 1), .cells(rows.count, 1).end(xlup)).value2 .range(.cells(1, 5), .cells(rows.count, 1).end(xlup).offset(0, application.match("zzz", .rows(1)) - 1)) .resize(.rows.count, .columns.count).offset(1, 0).clearcontents agrps = .cells.value2 end s = lbound(astrs, 1) ubound(astrs, 1) g = lbound(agrps, 2) ubound(agrps, 2) if cbool(instr(1, astrs(s, 1), agrps(1, g), vbtextcompare)) agrps(s + 1, g) = astrs(s, 1) exit end if next g next s .cells(1, 5).resize(ubound(agrps, 1), ubound(agrps, 2)) = agrps end end if '<<<< next sh '<<< apptggl end sub public sub apptggl(optional btggl boolean = true) debug.print timer application.screenupdating = btggl application.enableevents = btggl application.displayalerts = btggl application.calculation = iif(btggl, xlcalculationautomatic, xlcalculationmanual) end sub
Comments
Post a Comment