Syntax error (simple)

  • Thread starter Thread starter Jack Schitt
  • Start date Start date
J

Jack Schitt

I get a compile error "Invalid use of property on the "RefersTo" method.
What am I doing wrong, please?
I am trying to set a locally defined name "Header" on each worksheet in the
workbook to refer to $AZ$102:$BH$147
within the worksheet to which the respective name is localised.

Private Sub Fixnames()
Dim wWS As Worksheet
Dim R As Range
With Application.ThisWorkbook
For Each wWS In .Worksheets
Set R = wWS.Range("$AZ$102:$BH$147")
wWS.Names("Header").RefersTo R
Next wWS
End With 'Application.ThisWorkbook
End Sub 'Fixnames()
 
Wow! Instant response! thanks.

Chip Pearson said:
Jack,

RefersTo is a property, so you need an equals sign to assign a
value to it.

wWS.Names("Header").RefersTo = R


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Jack,

RefersTo is a property, so you need an equals sign to assign a
value to it.

wWS.Names("Header").RefersTo = R


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
If the name doesn't exist you need to add it. Assuming it does exist:

wWS.Names("Header").RefersTo = "=" & r.Address(External:=True)
 
Thanks T

Tom Ogilvy said:
If the name doesn't exist you need to add it. Assuming it does exist:

wWS.Names("Header").RefersTo = "=" & r.Address(External:=True)
 

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