Error message because of worksheet name

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Morning,
I have the code shown below.

I see messages like expected end of statement.
This is because the worksheet is called MC LIST

As a test i changed the name to LIST & its fine but why am i unable to have MC LIST

Does the space have any issues between the two words ?

Rich (BB code):
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
        Dim fndRng As Range
        Dim FindString As String
        Dim i As Integer
        Dim wsMC LIST As Worksheet
        
        FindString = Me.TextBox1.Value
        If Len(FindString) = 0 Then Exit Sub
        
        Set wsMC LIST = ThisWorkbook.Worksheets("LIST")
        i = 1
        Do
            Set fndRng = Nothing
            Set fndRng = wsMC LIST.Range("A:A").Find(What:=FindString & Format(i, " 000"), _
                                                        LookIn:=xlValues, lookat:=xlWhole, SearchOrder:=xlByRows, _
                                                        SearchDirection:=xlNext, MatchCase:=False)
            If Not fndRng Is Nothing Then
                i = i + 1
                Cancel = True
            End If
        Loop Until fndRng Is Nothing
        
        Me.TextBox1.Value = FindString & Format(i, " 000")
        Cancel = False
        
    End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
You cannot have a space in the name of a variable.
 
Upvote 0
Solution
No, you could use wsMC_LIST for example. The basic rules are:
  • You must use a letter as the first character.
  • You can't use a space, period (.), exclamation mark (!), or the characters @, &, $, # in the name.
  • Name can't exceed 255 characters in length
  • Avoid using names that are keywords in VBA or the object models you are using (some you can't use, the rest are just better avoided)
 
Upvote 0
Ok thanks,Its strange as other tabs are say MC NAME MC INFO etc etc & work fine.
I will do what youve advised

Thanks
 
Upvote 0
The variable name has nothing to do with what is on the tab of a worksheet.
 
Upvote 0
But in the vba code its shown as same as tab which is why i dont understand
 
Upvote 0
It can't be. You cannot have a space in a variable name.
 
Upvote 0

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

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