Reputation: 474
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.
Upvotes: 0
Views: 102
Reputation: 176
According with what you said this should work:
Dim cont As Integer
cont = 2
For j = 0 To 11
For i = 0 To 91
If Cells(2 + j, 2 + i) > 0 Then
Cells(16 + j, cont) = Cells(1, 2 + i)
cont = cont + 1
End If
Next i
Next j
Upvotes: 1