Excel VBA - Check whether a filtered table returns any results -


i have macro filters table (in code listobject) , copies visible cells in databodyrange seperate table. code works fine unless filtering action removes data (i.e. table has header row , nothing else).

is there neat way check whether rows visible? i'd avoid on error resume terms if possible, i'm struggling think of other way though?

i've included pseudocode below illustrate mean, assistance appreciated!

adam

if targettable.databodyrange.visiblerows.count > 0     targettable.databodyrange.specialcells(xlcelltypevisible).copy destination:=outputpasterange end if 

use table's range object, not databodyrange. then, check make sure .specialcells(xlcelltypevisible).rows.count > 1.

sub testemptytable() dim tbl listobject dim outputpasterange range dim tblisvisible boolean  set tbl = activesheet.listobjects(1) set outputpasterange = range("b15")  if tbl.range.specialcells(xlcelltypevisible).areas.count > 1     tblisvisible = true else:     tblisvisible = tbl.range.specialcells(xlcelltypevisible).rows.count > 1 end if  if tblisvisible     tbl.databodyrange.specialcells(xlcelltypevisible).copy _         destination:=outputpasterange  else:     msgbox tbl.name & " has been filtered no visible records", vbinformation  end if  end sub 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -