View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Using named Excel range in VBA

Without looking too close, it looks like you're passing a string to that
Format_Change function.

What happens if you try:
Sub format_change (MyRng as String, MyType as string)

I'm also confused about
With Sheets(MySht(i)).Range(CATr1).Validation

I see a string catlr, but no variable.

====
If myrng is a range, then
range(myrng) only makes sense if myrng is a single cell and holds something like
an address:
range("A1") (range(myrng.value))

And every range already has its own parent. So using:
worksheets("somesheet").myrng
won't work.

You could use something like this (depending on what you're doing):
worksheets("somesheet").range(myrng.address)
or
worksheets("somesheet").range(myrng.value)




wrote:

I have ranges named cat1r, cat2r, cat3r... cat28r on multiple
worksheets inside my workbook. I am trying to format the number style
of the ranges based upon the contents of corresponding combo boxes on
a "setup" worksheet.

sub Type1_click ()
format_change( "cat1r", type1.value)
end sub

sub Type2_click () ' ---------------------there
are 28 boxes and 28 range names
format_change( "cat2r", type2.value)
end sub
------

Sub format_change (MyRng as range, MyType as string)
dim MyShts
MyShts = array (........................ ' load array with
names of worksheets
if MyType= "Time"
For i = 0 to 15
With Sheets(MyShts(i)).Range(MyRng).Validation
<SNIP ' -----------
Validate to dropdown using time 0:00 to 8:00 by :15
Else
For i = 0 to 15
With Sheets(MySht(i)).Range(CATr1).Validation
<SNIP '
-------------------- Validate to 0-999
End If
End Sub

I keep gettinng a runtime error at the With statement in regards to
the range name.
please help


--

Dave Peterson