jeudi 26 février 2015

Continue For Next loop in separate cell

I have a table of number and I want to create a macro that will loop through each one, and return any value higher than 0.


The table would look something like this:



1 2 3 4 5 6 7 8 9 10 11 12 13 14
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2 0 0 0 0 2 0 0 0 0 0 0 0 0 7
3 0 0 0 0 0 0 0 0 0 0 0 0 0 0


And I would want it to return the column headers. So in that example I would want it to return the values 5 and 14 for the 2nd row.


So far I have:



For j = 0 To 11
For i = 0 To 91

If Cells(2 + j, 2 + i) > 0 Then
Cells(16 + j, 2) = Cells(1, 2 + i)
End If

Next i
Next j


The issue with this is that it will only return one value in cells(16 + j, 2), which is the last value that this corresponds to. What I need is, once the condition has been met, for it to continue from that point, but enter the value into cells(16 + j, 3).


I considered perhaps an "Exit For" once it had met the condition, but couldn't work out how to continue on the next cell from where it had left off.


Aucun commentaire:

Enregistrer un commentaire