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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

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,123,425
Messages
5,601,580
Members
414,460
Latest member
uctc

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top