Using Excel functions within VBA to define string variables

Scott JS

New Member
Joined
Aug 3, 2005
Messages
35
I am trying to define two variables for use in concatened instructions. The variables are the 1st 3 letters of the worksheet and the overall worksheet name. The code is bombing at the first SET command when I try to define the first variable:

Code:
    Dim dn As String
    Dim wsn As String
    Set dn = Mid(CELL("filename"), Find("]", CELL("filename")) + 1, 3)
    Set wsn = Mid(CELL("filename"), Find("]", CELL("filename")) + 1, 20)
The error returned is:
Compile Error:
Sub or Function not defined.

Note: the function “=Mid(CELL("filename"), Find("]", CELL("filename")) + 1, 3)” returns the first 3 letters of the name of the worksheet in question

No doubt this is a simple syntax issue, but it escapes me.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
String variables are not to be set.

Dim dn As String
Dim wsn As String
dn = Left(ActiveSheet.Name, 3)
wsn = ActiveSheet.Name


The above suggestion will do what you had in mind, assuming it's the active sheet. If it's not the active sheet you had in mind, you should use the CodeName property instead of the sheet tab name.
 
Upvote 0
Hi,

I am facing similar kind of problem when i use Find(":",sText) in my code like this.......

sChunk = Mid(sText, Find(":", sText) + 1, Find(".", sText) - 1)


the error refers to:
Sub, Function, or Property not defined (Error 35)

Can anyone explain it?
 
Upvote 0

Forum statistics

Threads
1,214,626
Messages
6,120,602
Members
448,974
Latest member
ChristineC

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
Back
Top