Offset and for next

voltrader

Board Regular
Joined
Dec 17, 2009
Messages
58
Office Version
  1. 2010
Platform
  1. Windows
Hey all,

I have a code that I am trying to expand to a range of about 20 rows by 2 columns. I would like for the macro to loop (?) through the entire range and offset each cells of the range 10 columns right, & 100 rows down.

Code:
Public Sub lmtpastespecial()
    ActiveSheet.range("a4:b4").Copy
    range("h4").PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
        Application.CutCopyMode = False
    ActiveSheet.range("c4:d4").Copy
    range("l4").PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
    ActiveSheet.range("f4:n4").Insert _
    shift:=xlDown
    range("n5").FormulaR1C1 = "=RC[-5]/RC[-1]"
        NumberFormat = "0.0000"
    ActiveSheet.range("f55:n55").ClearContents
End Sub

Any thoughts/opinions let me know!
 
This will copy each cell in YourRange to the cell offset'ed 10 columns and 100 rows:
Rich (BB code):
Sub LoopThroughRangeAndOffset()
Dim YourRange As Range
Set YourRange = Range("?") 'Type your range's address here i.e Range("A2:B21")
For Each Cell In YourRange
    Cell.Copy Cell.Offset(100, 10)
    Application.CutCopyMode = False
Next
End Sub
ZAX


Hey Zax, Thanks for the reply.
I'm still looking through the code, but it seems as if it is offsetting the first line in the range 100 rows down & than offsetting the next line 101 rows instead of 201 rows down. & is there a way to expand it from "For each cell in your Range" to multiple cells per row. To copy either 2 columns, or 4 columns at a time?
 
Last edited:
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hey Zax, Thanks for the reply.
I'm still looking through the code, but it seems as if it is offsetting the first line in the range 100 rows down & than offsetting the next line 101 rows instead of 201 rows down. & is there a way to expand it from "For each cell in your Range" to multiple cells per row. To copy either 2 columns, or 4 columns at a time?
Did you get a chance to try my code in Message #9 yet (I'm interested to know if it works or not)?
 
Upvote 0
Hey Rick, That works awesome!
I will work over the weekend to integrate my code to your sub.

Have a nice weekend!
 
Upvote 0
Hey Rick, Your code works great!

I'm kinda confused how it works, & I will def. try to extrapolate it over the weekend.

Thanks again!
 
Upvote 0
Hey Rick,

I am trying to add either paste special or .formula=.value to the line

Cells(StartRow, DataCol).Resize(, ColumnCount).Copy Cells(R, DataCol).Offset(RowOffset * (R - StartRow), ColOffset)

I cant seem to get the right object & syntax.

Thanks,
 
Upvote 0

Forum statistics

Threads
1,216,028
Messages
6,128,399
Members
449,447
Latest member
M V Arun

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top