excel vba - Delete row based on one letter -


need code. in (column c) have values mg01, mg02a, mg02b, mg02c. , in (column a) different values. code needs delete row if value in column "1" , in column c if finds letters @ end of text such b, c, d, e, ....

and "c" code not recognized mg02c please.

sub xdeleterowz()  last = cells(rows.count, "a").end(xlup).row = last 1 step -1     if (cells(i, "a").value) = "1" , (cells(i, "c").value) = "*c*"         cells(i, "a").entirerow.delete     end if next  end sub 

this sounds more suited regular expression:

sub xdeleterowz()     last = cells(rows.count, "a").end(xlup).row     createobject("vbscript.regexp")         .pattern = "mg\d{2}[a-z]"         .ignorecase = false         = last 1 step -1             if (cells(i, "a").value) = "1" , .test(cells(i, "c").value)                 cells(i, "a").entirerow.delete             end if         next     end end sub 

note expression requires value begin mg##. if start of value can different, replace line...

.pattern = "mg\d{2}[a-z]" 

...with...

.pattern = ".+[a-z]" 

... , match lowercase letter @ end. can limit specific letters changing range inside brackets. i.e., if it's 'a' through 'g', be:

.pattern = ".+[a-g]" 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -