Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

vba

ResolvedVersion 2007

Laura has attended:
Excel VBA Intro Intermediate course

VBA

How do you name a range of cells from within VBA.
For example, I would like the code to select cells A1:C1 and name the range "Headers"

Thanks

RE: VBA

Hi Laura,

Thank you for your question and welcome to the forum.

The following code belows names a range and copies and paste the range to another range of cells:

Range("c1:f1").Name = "TestThis" ' rename the range

Range("TestThis").Copy ' refer to the name and copy

Range("g1").PasteSpecial ' paste the named range

application.cutcopymode = false ' stops the marching ants around the selection copied

You can also use named ranges for Vlookup formulas.

I hope this answers your question.

Regards

Simon

Thu 15 Dec 2011: Automatically marked as resolved.

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Line breaks in a cell

You can control the line breaks for multiple-line headings or labels in your Microsoft Excel worksheet, just like you do in Microsoft Word. Here's how to do it.

Click the cell where you want the label or heading to appear.
Type the first line of information.
Press ALT+ENTER.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.13 secs.