If statement to check Excel cells in a Macro -


i'm trying if statement checks if given cell exists (some merged) , has value different of '-', statement executed, in case query. in case conditions not met, query not executed

cellstr = range("c3").text if cellstr <> "-" set rs = conn.execute("query") end if 

the code present works when cell has value '-' (the query not execute), not work when cell not exist (the query executes , returs 0)

how can protect if statement against issue?

check if cell exists (i.e. not covered merged cells) before check value/text in cell:

sub test()      dim c range     set c = range("c3") 'set cell      'check if cell exists, i.e. not covered merged cells     if c.mergearea.cells(1, 1).address = c.address          'check if cell text different "-"         if c.text <> "-"              'execute             msgbox "put statement here"          end if      end if  end sub 

best regards,

simon


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -