Quick VB function question

jferri

Board Regular
Joined
Jun 24, 2003
Messages
58
Quick Question.

In the below function, if "symbol" is the name of various worksheets in my workbook, why is the following function not working?

Thanks!


Public Function theValue(symbol As Variant)

theValue = Sheets(symbol).Cells(1, 5).Value

End Function
 

Some videos you may like

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Greg Truby

MrExcel MVP
Joined
Jun 19, 2002
Messages
10,014
That works for me. Though I would cast symbol as a String and not a variant.
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Try specifying symbol as a string rather than a variant - otherwise if the sheet name is a numerical value (like say '10') the function will actually look for the sheet in the activeworkbook with an index value of 10 rather than a name of '10'.

Richard
 

jferri

Board Regular
Joined
Jun 24, 2003
Messages
58
cool. it looks like i was being sloppy, and impatient. just needed to wait a bit longer.

thanks for the reply.
 

Watch MrExcel Video

Forum statistics

Threads
1,118,812
Messages
5,574,456
Members
412,595
Latest member
slim313
Top