View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
oaishm oaishm is offline
external usenet poster
 
Posts: 4
Default named ranges in building excel formulas from a string

Charles

I've read
VBA and Macros for Microsoft Excel by Mr Excel, Bill Jelen
The Excel bible series by John Wallenbach
Excel 2007 bible from wrox

I've also asked
The google message board for excel
Mr. Excel's message board
excelforum

NO ONE else had this answer. How could you have known this apparent arcana
of syntax when no one else in the world know it.

In any event. Thank you so much. I've been on this problem for four days.
The learning curve is unbelievably steep and I still don't understand why you
would need name.name. How would you even figure it out.

"Charles Williams" wrote:

The default property of a Name is its Refersto not its Name so you need to
use the not-very-obvious syntax of
QRange.Name.Name

Charles
___________________________________
The Excel Calculation Site
http://www.decisionmodels.com

"oaishm" wrote in message
...
I have two ranges named PReq and QOutput.

I have this procedu


Sub test_dependency()
Call dependency(Worksheets("PP"), [PReq], [QOutput], "testtitle")
End Sub


And I have:


Sub dependency(Result As Worksheet, Ratiorange As Range, Qrange As
Range, Title As String)
row_id = some array which results in a value
[Yearstart].value = 5
rowitem = 5
colitem = 5
z=10
Result.Cells(rowwriter, z).formula = "=vlookup(" & row_id(rowitem, 1)
& "," & Qrange.name & "," & z - [Yearstart].Value + 1 & ",false) *
index(" & Ratiorange.name & "," & rowitem & "," & colitem & ")"


I desperately want the formula to look like:


=vlookup(4,PReq,6,false)*index(QOutput,5,5)


I'll take


=vlookup(4,PReq!$b$5:$h$100,6,false)*index(QOutput !$b$5:$g$10,5,5)


but I get


=vlookup(4,=PReq!$b$5:$h$100,6,false)*index(=QOutp ut!$b$5:$g$10,5,5)


I've tried Qrange.name, .address, .value, .text anything. they all
dont' work. Then I tried to go through the Locals window and when I
clicked onto Qrange - Cells - Name, lo and behold, it was "QOutput".
So then I tried


?Qrange.cells.name in the immediate window and got a syntax error


same with:


?[Qrange].cells.name and ?Range("QRange").cells.name


Tell me your learning curve is as steep as mine because this should be
very obvious