excel vba - VBA Autofilter by whether a cell contains a number formatted as a string -
so writing macro sorts through sheet columns , clears cells containing kinds of data, if numeric. existing code catch number fields , clear them:
selection.autofilter field:=(i + 1), criteria1:=">0" range(cells(2, i), cells(70000, + 1)).select selection.clear worksheets("sheet1").showalldata selection.autofilter field:=(i + 1), criteria1:="=0" range(cells(2, i), cells(70000, + 1)).select selection.clear worksheets("sheet1").showalldata
which works fine cells contain numbers in number format. of cells contain numbers formatted strings, ie what
="80"
would produce when typed excel. need create criteria autofilter recognizes if cell contains number formatted string, dont know how, since criteria:=">0" , criteria:="=0" ignored strings.
another way :) have commented code if still have questions, feel free post back.
sub sample() dim rng range '~~> change relevant sheet sheet1 '~~> change format of column number '~~> example col '~~> change applicable .columns(1).numberformat = "0" '~~> convert number stored text number .columns(1).formula = .columns(1).value '~~> use special cells select cells containing numbers on error resume next set rng = .columns(1).specialcells(xlcelltypeconstants, xlnumbers) rng.clearcontents on error goto 0 end end sub
Comments
Post a Comment