ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How does .offset(i, counter) work? (https://www.excelbanter.com/excel-programming/351809-how-does-offset-i-counter-work.html)

Mike

How does .offset(i, counter) work?
 
Hi everypne,

How does the following piece of code work:

With Range("G2")
For i = 1 To 30
.Offset(i, ModelCounter) = Range("Picked").Cells(i)
Next
End With

In particular the offset line please!

Thanks,
Mike


Otto Moehrbach

How does .offset(i, counter) work?
 
Mike
The With/End With construct says that cell G2 is the reference cell.
The ".Offset(i, ModelCounter)" says "the cell that is "i" rows down and
"ModelCounter" columns to the right (if ModelCounter is positive) from G2.
HTH Otto
"Mike" wrote in message
oups.com...
Hi everypne,

How does the following piece of code work:

With Range("G2")
For i = 1 To 30
.Offset(i, ModelCounter) = Range("Picked").Cells(i)
Next
End With

In particular the offset line please!

Thanks,
Mike




dspencer[_6_]

How does .offset(i, counter) work?
 

With Range("G2")
For i = 1 To 30
.Offset(i, ModelCounter) = Range("Picked").Cells(i)
Next
End With


The above script enters data into cell G2 + i rows + ModelCounte
columns

And gets data from the range "Picked", cell number i.

So basically, it goes down the 30 rows according to i, taking the i't
cell from "Picked" and puts it in G2 + ModelCounter columns and
rows.

So if ModelCounter is 4, it will start in K3, K4, K5 .....

--
dspence
-----------------------------------------------------------------------
dspencer's Profile: http://www.excelforum.com/member.php...fo&userid=3096
View this thread: http://www.excelforum.com/showthread.php?threadid=50636


Mike

How does .offset(i, counter) work?
 
Dspencer,

As a follows up on the last line of your reply, say I want it to start
in K2 instead of K3,

What change should I make?

Thanks alot in advance,
Mike


Toppers

How does .offset(i, counter) work?
 
With range("G1")

would do.

"Mike" wrote:

Dspencer,

As a follows up on the last line of your reply, say I want it to start
in K2 instead of K3,

What change should I make?

Thanks alot in advance,
Mike




All times are GMT +1. The time now is 11:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com