Take active cell value in for loop and offset based on another cellvalue for columns to offset

B

burl_h

I have the following incomplete macro, where a user selects a range.
We then loop through the range going thru each column in first row of
range then down to next row and across each column etc. etc.

When I hit a cell who's value is > 0, it want to take that value and
place it in a cell offset from the active cell inside for loop. The
column offset will come from current row (in for loop) and column b.
The row offset i would envision as being some constant value let say
10 for arguments sake.

For example, let say my selected range is C2:M10
My first cell within range > 0 is H2
In cell B2 lets say it's 4
Now we want to take the value from H2 and place it in D12 (the 4 in B2
will offset the active cell by 4 columns to the left and the constant
10 offset the rows from active cell by 10. The for loop will then
continue until we hit the next cell >0. Assuming we are still on row 2
the offset value for columns remains B2, but once we loop to next row
the offset for column would be B3 etc etc.

In the code below i'm having difficulty putting into code what i
describe above, hopefully someone can help.


Sub Test()

Dim row As Range
Dim cell As Range

Dim UserRange1 As Range
On Error GoTo Canceled
Set UserRange1 = Application.InputBox(Prompt:="Please Select Range",
Title:="Range Select", Type:=8)

For Each row In UserRange1.Rows
For Each cell In row.Cells
If cell > 0 Then

this is where i came unstuck...........

End If
Next cell
Next row
Canceled:

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top