Continue macro on next row

Reefer

New Member
Joined
Jul 24, 2012
Messages
4
Hi there,

I am new to VBA and have this code

Sub Rename()

'Rename
Range("F2:P2").Name = Range("B2")

End Sub

Can someone tell me how to progress this automatically to the next row eg:

Range("F3:P3").Name = Range("B3')

etc, and so on to say about 2000.

Hope this makes sense.
Thanks in advance
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Rich (BB code):
Sub Rename()

For Each rng in Range("F2:P200").Rows
    'Rename
    rng.Name = Range("B" & rng.Row)
Next
End Sub

Did you also investigate the built-in functionality of inserting names automatically?
 
Upvote 0
Rich (BB code):
Sub Rename()

For Each rng in Range("F2:P200").Rows
    'Rename
    rng.Name = Range("B" & rng.Row)
Next
End Sub

Did you also investigate the built-in functionality of inserting names automatically?

Thanks heaps wigi,

Couldnt get the code to work, but I made a code out of the automatical entering and works like a charm!
I can't believe I spent all day looking for this and you gave me the answer within a couple of mins.
Thanks again.
 
Upvote 0
My code example works fine.
I can only imagine that column B contains invalid names, and as such the macro does not work 100%.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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