|
-
Aug 16th, 2007, 09:43 AM
#1
Thread Starter
New Member
[Resolved] Naming Cell, dynamically defined by string
Hi, I'm attempting to name a particular cell, based on a string.
Code:
Dim CellName As String
Dim extendedName As String
' Somewhere CellName has been set, eg
CellName = "H25"
ActiveWorkbook.Names.Add Name:="Total", RefersToR1C1:= _
"='Report 5'!" & CellName
This gives me extra apostrophes around CellName. eg:
Total ='Report 5'!'H25'
So I tried defining the whole string first:
Code:
extendedName = "'Report 5'!" & CellName
ActiveWorkbook.Names.Add Name:="Total", RefersToR1C1:= extendedName
However, this then added quotation marks around the entire formula, eg:
Total ="'Report 5'!H25"
Does anyone know how to do this? It seems like I'm overlooking something really simple.
Last edited by jkmyoung; Aug 16th, 2007 at 02:34 PM.
-
Aug 16th, 2007, 10:49 AM
#2
Fanatic Member
Re: Naming Cell, dynamically defined by string
Welcome to the forums!
Try this:
Code:
cellname = "$H$25"
ActiveWorkbook.Names.Add Name:="Total", RefersTo:="=Report!" & cellname
The $'s are needed, otherwise the reference will be relative to cell position.
Last edited by VBAhack; Aug 16th, 2007 at 10:58 AM.
-
Aug 16th, 2007, 12:49 PM
#3
Thread Starter
New Member
Re: Naming Cell, dynamically defined by string
Ok. That's a good tip. It doesn't entirely solve the problem, there are still extra quotes or apostrophes either way.
I think the problem may be more related to the fact that my sheet name needs to be surrounded in single quotes. Unfortunately, I am unable to rename this sheet.
Update:
ok removing the R1C1 at the end fixed it. Thanks.
How does one resolve a thread?
Last edited by jkmyoung; Aug 16th, 2007 at 02:33 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|