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
 
Nope the edit was changing "For c = 1 to 6" to "For c = 1 to 7" to match Ede's information on # of columns involved.
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Nope the edit was changing "For c = 1 to 6" to "For c = 1 to 7" to match Ede's information on # of columns involved.
I must be losing it! It is time to go home! :roll:

EdE, Greg's code should do what you want.
 
Upvote 0
Greg,
Code:
Sub foofoo()
    Dim c%, r%
    On Error Resume Next
    For c = 1 To 7
        For r = 1 To 13 Step 2
            Cells(r + 1, c).Name = Cells(r, c).Value
        Next r
    Next c
End Sub


What does the % symbol (c%, r%) do in your posted code?

Thank You,

Dan
 
Upvote 0
It isnt working. I step through the code, but nothing happens.

I have this code

Sub nametest()
Dim c
Dim r
On Error Resume Next
For c = 1 to 13 step 2
Cells(r, c + 1).Name = Cells (r,c).Value
Next c
End c

None of the cells have names that were in that range. What am I doing wrong?
 
Upvote 0
EdE

Check again, it worked for me.
Click on Cell A2 and look in the Name Box.
It will show the value of A1.

Datsmart
 
Upvote 0
I tried starting new workbook. it still doesnt work for me. Could this have anything to do with excel 2003?
Do I need to define a starting spot? When I step through, and can see the spreadsheet, I dont even see the cursor move. This is driving me crazy.
 
Upvote 0
The cursor is not going to move. Nothing is being selected. That is why it runs so fast. The Named Ranges are assigned by the VBA code.
Go to Insert-> Name-> Define
You will see all your named ranges.
 
Upvote 0
text

WHen I record a macro, i get this:
ActiveWorkbook.Names.Add Name:="CellName", RefersToR1C1:= _
"=Details!R637C69"

Only if I copy the contents of R637C68 and paste into the name field.
 
Upvote 0

Forum statistics

Threads
1,224,893
Messages
6,181,616
Members
453,057
Latest member
LE102024

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