ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problem creating a named range (https://www.excelbanter.com/excel-programming/414694-problem-creating-named-range.html)

headly

Problem creating a named range
 
Code looks like this:

ActiveWorkbook.Names.Add Name:=varName, RefersTo:="Sheet!" & varStartCell


Creates a name, which I cannot use, because it is surrounded by quotation "
" symbols.
Note about Varname: is created after stripping out spaces from user entered
input; varStartCell is an absolute reference like $A$5

TY

Dave Peterson

Problem creating a named range
 
Do you have a worksheet named: Sheet

And you dropped an equal sign in the refersto:= portion

RefersTo:="=Sheet!" & varStartCell

headly wrote:

Code looks like this:

ActiveWorkbook.Names.Add Name:=varName, RefersTo:="Sheet!" & varStartCell

Creates a name, which I cannot use, because it is surrounded by quotation "
" symbols.
Note about Varname: is created after stripping out spaces from user entered
input; varStartCell is an absolute reference like $A$5

TY


--

Dave Peterson

Ron Rosenfeld

Problem creating a named range
 
On Sun, 27 Jul 2008 16:49:29 -0700, headly
wrote:

Code looks like this:

ActiveWorkbook.Names.Add Name:=varName, RefersTo:="Sheet!" & varStartCell


Creates a name, which I cannot use, because it is surrounded by quotation "
" symbols.
Note about Varname: is created after stripping out spaces from user entered
input; varStartCell is an absolute reference like $A$5

TY


You're very close to the correct format. Note the equal sign AFTER the initial
quote.

ActiveWorkbook.Names.Add Name:=varName, RefersTo:="=Sheet!" & varStartCell
--ron

Leith Ross[_2_]

Problem creating a named range
 
On Jul 27, 5:48 pm, Dave Peterson wrote:
Do you have a worksheet named: Sheet

And you dropped an equal sign in the refersto:= portion

RefersTo:="=Sheet!" & varStartCell

headly wrote:

Code looks like this:


ActiveWorkbook.Names.Add Name:=varName, RefersTo:="Sheet!" & varStartCell


Creates a name, which I cannot use, because it is surrounded by quotation "
" symbols.
Note about Varname: is created after stripping out spaces from user entered
input; varStartCell is an absolute reference like $A$5


TY


--

Dave Peterson


Hello headly,

If you need the active sheet's name added to the reference, you can
use this code..

ActiveWorkbook.Names.Add Name:=varName, RefersTo:="='" &
ActiveSheet.Name & "'!" & varStartCell

Sincerely,
Leith Ross

Gary''s Student

Problem creating a named range
 
You are missing an equals sign:

Sub Macro1()
Dim varName As String
Dim varStartCell As String
varName = "alpha"
varStartCell = "$A$5"
ActiveWorkbook.Names.Add Name:=varName, RefersTo:="=Sheet!" & varStartCell
End Sub
--
Gary''s Student - gsnu200796


"headly" wrote:

Code looks like this:

ActiveWorkbook.Names.Add Name:=varName, RefersTo:="Sheet!" & varStartCell


Creates a name, which I cannot use, because it is surrounded by quotation "
" symbols.
Note about Varname: is created after stripping out spaces from user entered
input; varStartCell is an absolute reference like $A$5

TY


headly

Problem creating a named range
 
Actually, no, I get a name like ="sheet1!$A$5" but no idea where the "" came
from

"Gary''s Student" wrote:

You are missing an equals sign:

Sub Macro1()
Dim varName As String
Dim varStartCell As String
varName = "alpha"
varStartCell = "$A$5"
ActiveWorkbook.Names.Add Name:=varName, RefersTo:="=Sheet!" & varStartCell
End Sub
--
Gary''s Student - gsnu200796


"headly" wrote:

Code looks like this:

ActiveWorkbook.Names.Add Name:=varName, RefersTo:="Sheet!" & varStartCell


Creates a name, which I cannot use, because it is surrounded by quotation "
" symbols.
Note about Varname: is created after stripping out spaces from user entered
input; varStartCell is an absolute reference like $A$5

TY


OssieMac

Problem creating a named range
 
Put a stop in your code just before naming the range like the following then
while it is stopped and before cancelling the process, rest your cursor over
the variables varName and then varStartCell and see what value VBA has
assigned to them.

varName = "MyNamedRange" 'Just as demo. No doubt your code is different
varStartCell = "$A$5"

Stop

ActiveWorkbook.Names.Add Name:=varName, RefersTo:="Sheet!" & varStartCell


If you can't fix then post a bit more of your code showing how varName and
varStartCell are populated and manipulated. ie stipped of blanks etc.

--
Regards,

OssieMac


"headly" wrote:

Actually, no, I get a name like ="sheet1!$A$5" but no idea where the "" came
from

"Gary''s Student" wrote:

You are missing an equals sign:

Sub Macro1()
Dim varName As String
Dim varStartCell As String
varName = "alpha"
varStartCell = "$A$5"
ActiveWorkbook.Names.Add Name:=varName, RefersTo:="=Sheet!" & varStartCell
End Sub
--
Gary''s Student - gsnu200796


"headly" wrote:

Code looks like this:

ActiveWorkbook.Names.Add Name:=varName, RefersTo:="Sheet!" & varStartCell


Creates a name, which I cannot use, because it is surrounded by quotation "
" symbols.
Note about Varname: is created after stripping out spaces from user entered
input; varStartCell is an absolute reference like $A$5

TY


Ron Rosenfeld

Problem creating a named range
 
On Sun, 27 Jul 2008 18:27:02 -0700, headly
wrote:

Actually, no, I get a name like ="sheet1!$A$5" but no idea where the "" came
from


If you put in the "=" sign where we have all been telling you to, those "" will
go away.
--ron


All times are GMT +1. The time now is 05:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com