PDA

View Full Version : Solved: Offset help



Tvercetti
10-30-2007, 06:15 PM
:banghead: :banghead:
Hey

If I have a loop and and am using an offset and I want to go down 6 cells through each loop how do I do this?

So copy A3 ... next, copy A9, and so on...
Actually 8 times

herzberg
10-30-2007, 06:28 PM
It can be done with a For... Loop, something like this:

With Activesheet
For Counter = 1 to 60 Step 6
.Cells(Counter, 1).Copy .Cells(Counter, 2)
Next Counter
End With
The above assumes that I have 60 rows in Column A and I only want every 6th record to be copied to Column B, i.e. 1, 6, 12...etc.

malik641
10-30-2007, 06:30 PM
Take a look at this:

Public Sub TryMe()
Dim i As Long, j As Long, k As Long

' Start offset values
i = 3
j = 0

' Loop to copy
For k = 1 To 8 ' 8 being the number of trials
' Using Cells method
Debug.Print Worksheets("Sheet1").Cells(i, "A").Address
' Using Offset method
Debug.Print vbTab & Worksheets("Sheet1").Range("A3").Offset(j, 0).Address

i = i + 6
j = j + 6
Next
End Sub
View the results in the Immediate Window (CTRL-G in VBE) in the VBE (ALT+F11 in Excel).

EDIT: Sorry herzberg, I didn't refresh before I posted.