excel - How to select a Column based on the Header value using VBA -


i working on deleting rows if particular value not found in column.

example excel data is

sl.no     content 1         apple 2         ball 3         cat 4         ball 5         cat 

and code using is

sub delete()  dim startrow long 'starting row number here startrow = 2 ' assuming data check in column until startrow > cells(cells.rows.count, "a").end(xlup).row     if cells(startrow, 2).value = "ball"         rows(startrow).delete     else         startrow = startrow + 1     end if loop  end sub 

the output of code is

sl.no     content 1         apple 3         cat 5         cat 

this code working perfect. need small change here. trying select b column using column header 'content' , delete rows containing 'ball' instead of providing cell number.

please me in arriving @ this. tia

sub delete()      dim startrow long     dim rng1 range     'starting row number here     startrow = 2     ' assuming data check in column     set rng1 = activesheet.usedrange.find("content", , xlvalues, xlwhole)     if not rng1 nothing         until startrow > cells(cells.rows.count, "a").end(xlup).row             if cells(startrow, rng1.column).value = "cat"                 rows(startrow).delete             else                 startrow = startrow + 1             end if         loop     else         msgbox "column not found", vbcritical     end if  end sub 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -