Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA naming Excel Ranges

Status
Not open for further replies.

Chance1234

IS-IT--Management
Jul 25, 2001
7,871
US
why doesnt this work

Public sub psubnamemyrange(strran1,strran2,strsht,intr)

ActiveWorkbook.Names.Add Name:=stRran1, RefersToR1C1:="=" & stRsht & "!R" & IntR + 1 & "C2"
ActiveWorkbook.Names.Add Name:=STrran2, RefersToR1C1:="=" & stRsht & "!R3C2:R" & IntR & "C2"

end sub

when this does work

public sub subnameoneofmyrange
ActiveWorkbook.Names.Add Name:="NewLineb", RefersToR1C1:="=ccdata!R" & IntR + 1 & "C2"
ActiveWorkbook.Names.Add Name:="NewListb", RefersToR1C1:="=ccdata!R3C2:R" & IntR & "C2"
end sub

Filmmaker, gentlemen and East end club promoter



 
Does stRsht perchance contain a space? If not, can you evaluate your refersto string (by printing it in the immediate window) and let us know what it is?
Rob
[flowerface]
 
Rob is correct -- it the sheet name has a space, then you need tic marks around the sheet name
Code:
ActiveWorkbook.Names.Add Name:=stRran1, RefersToR1C1:="='" & stRsht & "'!R" & IntR + 1 & "C2"
ALSO...

If stRran1 or STrran2 have spaces, it will NOT work. The spaces (and other non alpha-numeric characters) must be replaced by underscore. Skip,
Skip@TheOfficeExperts.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top