excel vba - VBA to check if mutiple ranges are blank and enter data if first cell of each range that is blank -
i need macro @ 6 specific ranges:
("f15:f4999") ("h15:h4999") ("j15:j4999") ("l15:l4999") ("n15:n4999") ("p15:p4999")
if 1 or more of these ranges blank, need macro enter "no data" in first cell of blank range(s) (i.e. in f15). ranges contain various types of data include text, dollar values, dates, , percentages.
this macro part of it's own module, , called @ end of macro.
i have tried using counta function, hung due type mismatch errors. following works, first blank range each time run it. (i.e. if column f blank, enter "no data", not continue on , enter "no data in blank columns follow)
sub fillfetchdatablanks() application.screenupdating = false application.enableevents = false sheets("graph data").select if application.worksheetfunction.counta(range("f15:f4999")) <= 0 [f15] = "no data" elseif application.worksheetfunction.counta(range("h15:h4999")) <= 0 [h15] = "no data" elseif application.worksheetfunction.counta(range("j15:j4999")) <= 0 [j15] = "no data" elseif application.worksheetfunction.counta(range("l15:l4999")) <= 0 [l15] = "no data" elseif application.worksheetfunction.counta(range("n15:n4999")) <= 0 [n15] = "no data" elseif application.worksheetfunction.counta(range("p15:p4999")) <= 0 [p15] = "no data" else on error resume next end if [b15].select application.screenupdating = true application.enableevents = true end sub any and/or advice appreciated!
thank you,
john
you have use separate ifs i.e not combine them using elseif.
try this
with application.worksheetfunction if .counta(range("f15:f4999")) <= 0 [f15] = "no data" if .counta(range("h15:h4999")) <= 0 [h15] = "no data" if .counta(range("j15:j4999")) <= 0 [j15] = "no data" if .counta(range("l15:l4999")) <= 0 [l15] = "no data" if .counta(range("n15:n4999")) <= 0 [n15] = "no data" if .counta(range("p15:p4999")) <= 0 [p15] = "no data" end this way don't need else , end if
Comments
Post a Comment