Range Offset Error

N

NetWave128

After I run it; the value are placed in a stair step down, as in th
next range "F8" starts in "H8" its not right....

I would like to run this:

For Each cell In MyRange2
If cell.Value > 0 Then
myrange.Offset(0, x) = cell.Value
x = x + 1
End If
Next cell

down multiple rows...same for each loop...

please help

CODE PASTED BELOW



Sub Benchmark()
Dim myrange As Range
Dim x As Integer
Dim MyRange2 As Range
Dim t As Integer
x = 0

For t = 0 To 44
Set MyRange2 = Sheets("appendix").Range("p7:cq7")
Set MyRange2 = MyRange2.Offset(t, 0)
Set myrange = Sheets("appendix").Range("f7")
Set myrange = myrange.Offset(t, 0)

For Each cell In MyRange2
If cell.Value > 0 Then
myrange.Offset(0, x) = cell.Value
x = x + 1
End If
Next cell
Next t

Set MyRange2 = Nothing
Set myrange = Nothing

End Su
 
C

Charles

NetWave182

I think you need to change your code to:


For Each cell In MyRange2
If cell.Value > 0 Then

x = x + 1<<<<<<< Move to here.....
myrange.Offset(0, x) = cell.Value

End If
Next cell


Charle
 
G

George Nicholson

Offset(RowOffset,ColumnOffset) not (Column, Row). Hard to say if you have
this backwards or not.
 

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