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

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -