excel vba - How to delete the blank sheets in the given workbook? -
sub deleteemptysheets() dim sh worksheet, wb workbook, c range sh = sheets(wb.sheets) each c in wb.sheets if isempty(sh.usedrange) sh.delete end if next set sh = nothing set wb = nothing set c = nothing end sub
question:i tried delete empty sheets, not able exact code. can me in case? thanks.
you're not defining wb
comes from, , you're not using sh
iterate through sheets.
i'm assuming want iterate through sheets in active workbook. if so, don't need wb
or c
. try this:
sub deleteemptysheets() dim sh worksheet each sh in activeworkbook.sheets if isempty(sh.usedrange) sh.delete end if next set sh = nothing end sub
Comments
Post a Comment