Offset in VBA

EdE

Board Regular
Joined
Apr 8, 2002
Messages
241
How do I skip cells in VBA?
Say, I am starting at A1, perform task,then want to move to a2, perform task, then move to a3. I want to do this without using absolutes. I need to do this in various areas 7 times before I move to the next area. Any ideas?
Thanks!
Ed
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
The Text you have listed:
"R637C68" is your problem. You can not name a range using reserved words or anything that could be confused with a Cell address. "R637C68" fits the cell address category.
 
Upvote 0
Code I am using that doesnt work:
Sub nametest()
Dim c%, r%
On Error Resume Next
For c = 1 to 13 step 2
Cells(r, c + 1).name = Cells(r, c).value
Next c
End Sub


This is the code I get when I record a macro:
ActiveWorkbook.Names.Add Name:="CellName", RefersToR1C1:= _
"=Details!R637C69"

This is doing the following: copy R637C69 (which contains "CellName"), then Insert Name Define, then Paste in the name box, and click ok.

Am I missing something in the first one at all?
 
Upvote 0
Okey doke -- if you're a-gettin' R637C69 den you ain't a working in cells A1:G14 like we was first led to believe. You would need to alter the row and column references per the range of cells being targeted. For example if you want to apply this to BQ637:BW650 then the column loop would be:

for c = 69 to 75

and the row loop would be

for r = 637 to 649 step 2

Please note that in your last post the snippet of code was not good; (you had the column loop stepping by 2 and the row loop was AWOL).
 
Upvote 0

Forum statistics

Threads
1,215,773
Messages
6,126,821
Members
449,340
Latest member
hpm23

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