How to apply OFFSET as the range in a basic 'Copy' process...
As you are learning VBA, shed yourself of the notion you need to SELECT a
range to act on it. Truth is you RARELY need to select ranges in VBA.
Now, to use OFFSET in VBA, it is of the syntax
RANGE("A10").OFFSET(#rows,#cols)
or
CELLS(10,1).OFFSET(#rows,#cols)
In this example you end up with a 1 by 1 range. It's identical in size to
your original reference, A10 being a single cell. If you need a different
sized range you use
RANGE("A10").OFFSET(#rows,#cols).RESIZE(how many rows tall, how many columns
wide)
To rewrite your code
Cells(12,8).OFFSET(7,6).resize(3,2).COPY
"cdavidson" wrote:
Simply looking to understand how to properly apply the offset command to
identify a range in VBA coding. The respective portion of my 'improper' code
is shown below. What should the 'Range("...' line of code be? Thanks!
Sub PivotConcept()
Sheets("Pivots").Select
Range("(OFFSET(R12C8,7,6,3,2)").Select
Selection.Copy
.
.
.
End Sub
|