excel - How to avoid subset out of range when running a delete rows with variable -


i know may have been asked in various formats, new coding , don't understand how apply function.

i keep getting subscript out of range error message when running vba.

sub keeponlyatsymbolrows()      dim ws worksheet     dim rng range     dim lastrow long      set ws = activeworkbook.sheets("sheet1")      lastrow = ws.range("a" & ws.rows.count).end(xlup).row      set rng = ws.range("a1:a" & lastrow)      rng         .autofilter field:=1, criteria1:="<>*international sbu*"         .offset(1, 0).specialcells(xlcelltypevisible).entirerow.delete     end     ws.autofiltermode = false end sub 

for context sheet @ moment 178 rows long , goes ak number of rows vary each update number of columns won't

be careful when hard code name of sheets :

set ws = activeworkbook.sheets("sheet1") 

because if change name in excel, you'll have in code (you'll find out pretty shortly error message)

so different ways call/reference sheet :

classical, sheet's name

set ws = activeworkbook.sheets("sheet1") 

using index

set ws = activeworkbook.sheets(1) 

using sheet's object name

set ws = activeworkbook.sheet1 

that name won't change, if rename sheet directly in excel!

enter image description here


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -