Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Reducing "Set" statements

I have multiple named ranges which are referred to in code. To use these
ranges I use a series of "Set" statements near the start of my code.

eg
With Worksheets("Lookup")
Set GeneralTubeCount = .Range("GeneralTubeCount")
Set GeneralkVmAs = .Range("GeneralkVmAs")
Set GeneralField = .Range("GeneralField")
Set GeneralFieldVB = .Range("GeneralFieldVB")
etc
etc
etc
End With

Is there a way to reduce the code down given that the "Set" and "Range"
names are always the same?

I've tried the following code but it fails with "Run-time error 438 - Object
doesn't support this property or method"

Sub test()
Set nms = ActiveWorkbook.Names
With Worksheets("Lookup")
For r = 1 To nms.Count
Set nms(r).Name = .Range(nms(r).Count) 'crashes on this line
Next
End With
End Sub

Any ideas?

--
Ian
--


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Reducing "Set" statements

Sorry. Mistake in my code, but still the same result.

Sub test()
Set nms = ActiveWorkbook.Names
With Worksheets("Lookup")
For r = 1 To nms.Count
Set nms(r).Name = .Range(nms(r).Name) 'crashes on this line
Next
End With
End Sub

--
Ian
--

"IanC" wrote in message news:Kob9o.38$qQ6.10@hurricane...
I have multiple named ranges which are referred to in code. To use these
ranges I use a series of "Set" statements near the start of my code.

eg
With Worksheets("Lookup")
Set GeneralTubeCount = .Range("GeneralTubeCount")
Set GeneralkVmAs = .Range("GeneralkVmAs")
Set GeneralField = .Range("GeneralField")
Set GeneralFieldVB = .Range("GeneralFieldVB")
etc
etc
etc
End With

Is there a way to reduce the code down given that the "Set" and "Range"
names are always the same?

I've tried the following code but it fails with "Run-time error 438 -
Object doesn't support this property or method"

Sub test()
Set nms = ActiveWorkbook.Names
With Worksheets("Lookup")
For r = 1 To nms.Count
Set nms(r).Name = .Range(nms(r).Count) 'crashes on this line
Next
End With
End Sub

Any ideas?

--
Ian
--





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
Need more than 7 nested "IF" statements in Excel" James A Excel Discussion (Misc queries) 1 December 17th 06 02:02 AM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM


All times are GMT +1. The time now is 01:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"