View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] mgray@trgusa.com is offline
external usenet poster
 
Posts: 3
Default Range name as varible

I am having trouble understanding why this sub works when used
Range("name") but not Range(NameAsVar). See below. any ideas how to
make this work? Do I have to convert the strings passed to a range
object? How would i do that?


Sub SubstituteVals(var1name As String, var2name As String, _
var1val As Double, var2val As Double)

'Works with specific named ranges

'Range("PurchasePrice") = var1val
'Range("GrossSalesTotal") = var2val

'Does not work if range name is a varible
'Method 'Range' of Object '_Global' failed

Range(var1name) = var1val
Range(var2name) = var2val

End Sub