0

I have a small/complex problem, but I cannot understand why I'm obtaining this error.

In a vba code I have this:

ws = Sheets("Calendar") c = "Fixed" first = ce.Address end = ce2.Address wb.Names.Add Name:=c, RefersTo:=ws.Name & "!" & first & ":" & end 

The formula create a named range like this one:

="Calendar!$M$2:$M$4" 

This named range doesn't show any values, but if I change manually the named range in this:

=Calendar!$M$2:$M$4 

It will work.

Where is the issue? Why the formula doesn't work? Which parameter is wrong?

Thanks

1
  • Multiple issues with your code. ws = Sheets("Calendar") should be Set ws = Sheets("Calendar") and end cannot be a variable name. But the main issue is that the string for RefersTo:= must begin with an equal sign. See msdn.microsoft.com/en-us/library/office/ff834743.aspx. Commented Mar 28, 2016 at 12:22

1 Answer 1

1
  1. end is not a good variable name
  2. ws is an object, so Set should be used to assign it
  3. The formula needs a "=" in front of it

Set ws = Sheets("Calendar") c = "Fixed" first = ce.Address end1 = ce2.Address wb.Names.Add Name:=c, RefersTo:="=" & ws.Name & "!" & first & ":" & end1

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

1 Comment

I have translated "first" and "end" without thinking about it. In the original code the name was different. The missing "=" was the problem. Thank you!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.