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
 

Some videos you may like

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,950
Office Version
365
Platform
Windows, Mobile, Web
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?
 

Reefer

New Member
Joined
Jul 24, 2012
Messages
4
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.
 

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,950
Office Version
365
Platform
Windows, Mobile, Web
My code example works fine.
I can only imagine that column B contains invalid names, and as such the macro does not work 100%.
 

Watch MrExcel Video

Forum statistics

Threads
1,098,846
Messages
5,465,049
Members
406,410
Latest member
Di27

This Week's Hot Topics

Top