vba - run-time error '1004': method 'range' of object '_global' failed for method that works error-free in another context -
i have issue following lines giving me run-time error referenced in title, first line of if statement being highlighted culprit:
sub setupfirstworksheet() = 0 worksheets(1).usedrange.rows.count if range("h" & i).value = 1010 or range("j" & i).value < 0 or range("k" & i).value = false [some code or blank] end if next end sub
however, putting in similar code below, have no issues:
sub test() = 0 worksheets(1).usedrange.rows.count next msgbox range("h" & i).value end sub
any appreciated. thank you.
you starting loop @ 0, means generating range references h0,j0 & k0. these invalid because there no such thing row 0.
change loop start @ 1 , okay.
the reason test works because msgbox line executed after loop has finished, , equal worksheets(1).usedrange.rows.count
. if move msgbox statement loop, find fail.
Comments
Post a Comment