Having a problem using a variable to add a 'name'

  • Thread starter Thread starter Kobayashi
  • Start date Start date
K

Kobayashi

Okay, to get this working I've had to change the davv... reference t
the actual worksheet name instead, like: 'Validation Values'!C1. Stil
can't understand why I can't just reference a variable but I need t
get the working. I'm sure it's something quite basic and fundamental i
relation to the way you should use/declare variables so I would stil
appreciate any advice to prevent similar issues in the future?

Thanks,

Adria
 
if davvsheet is a variable holding the text Sheet2

then

Sub BBTest()
Dim DAbook as Workbook
Dim davvsheet as String
davvsheet = "Sheet2"
Set DAbook = Workbooks("Book1.xls")
DAbook.Names.Add Name:="Lookuplist2", RefersToR1C1:= _
"=" & davvsheet & "!c1"
End Sub

would work, but you were already given that answer???

a possibibility is that the sheet name has a space in it. Then you would
need

"='" & davvsheet & "'!c1"

so the name will be enclosed in single quotes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top