2

I have a named range that is called tempPrintArea and refers to

='Label packinglist'!$A$1:$J$59

I want to use VBA to add another selection to it, so that it refers to

='Label packinglist'!$A$1:$J$59,'Label packinglist'!$A$61:$J$110

How can I do this?

I'm envisioning something like

Range("tempPrintArea").RefersTo = wks.Range("tempPrintArea").Address & wks.Range("$A$61:$J$110")

... but that doesn't work

2
  • do you want to add reference to exiting named range or create new named range? Commented Apr 11, 2014 at 12:57
  • I want to add the reference to the existing named range called tempPrintArea Commented Apr 11, 2014 at 12:58

1 Answer 1

4

Suppose that you've created named range like this:

Dim wks As Worksheet
Set wks = ThisWorkbook.Worksheets("Label packinglist")

wks.Names.Add Name:="tempPrintArea", RefersTo:=wks.Range("A1:J59")

next step is to add new reference to it:

wks.Names("tempPrintArea").RefersTo = Union(wks.Range("tempPrintArea"), wks.Range("A61:J110"))

and now

Dim test As String
test = wks.Range("tempPrintArea").Address ' returns $A$1:$J$59,$A$61:$J$110

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

No need for two steps. The second step will overwrite any existing name, so it is all you need.
@ExcelDevelopers, I know, first part follows from another OP's question: stackoverflow.com/questions/23012097/… and I've decided to leave it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.