[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Define Names in  a Loop

Posted on 2011-03-05
5
Medium Priority
?
416 Views
Last Modified: 2012-05-11
Hi
See attached.
The sheet explains  my query.

Thanks !
DefineNamesQuery.zip
0
Comment
Question by:Patrick O'Dea
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 24

Accepted Solution

by:
StephenJR earned 1600 total points
ID: 35043917
Do you meant like this?
Sub x()

Dim r As Range

For Each r In Range("A2", Range("A2").End(xlDown))
    r.Offset(, 1).Name = "Customer_" & r
Next r

End Sub

Open in new window

0
 
LVL 45

Expert Comment

by:patrickab
ID: 35043990
21Dewsbury,

Please state your question rather than expect people to open a file to discover what your question really is.

Patrick
0
 

Assisted Solution

by:Patrick O'Dea
Patrick O'Dea earned 0 total points
ID: 35044439
Point taken Patrickab,
However, I felt that in this case a "picture paints a thousand words".

In other words it was easier to understand by viewing the sheet rather than a more lengthy (and confusing?) written explanation.
Perhaps this does not suit all.
0
 
LVL 14

Expert Comment

by:Zack Barresse
ID: 35045012
Rather than keep invoking the name method of the workbook, you can test it's existence first.  On a small operation you may not notice a difference, but could over large data sets.
Sub NameMyRangesPlease()
    Dim WS As Worksheet, rCell As Range
    Set WS = ThisWorkbook.Sheets("Sheet1")
    For Each rCell In WS.Range("A2", WS.Cells(WS.Rows.Count, 1).End(xlUp))
        If NameExists("Customer_" & rCell.Value) = False Then
            rCell.Offset(0, 1).Name = "Customer_" & rCell.Value
        End If
    Next rCell
End Sub

Function NameExists(sRangeName As String) As Boolean
    On Error Resume Next
    NameExists = Len(ThisWorkbook.Names(sRangeName).Name) <> 0
End Function

Open in new window

0
 

Author Closing Comment

by:Patrick O'Dea
ID: 35107032
Thanks StephenJR,

That's perfect.

Now I will have to ensure that I can understand the code.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question