WorksheetExists Sub or Function not defined error

Gliffix101

Board Regular
Joined
Apr 1, 2014
Messages
81
Hello All,

I have been running this code for a few weeks now but today I made some variable changes in other fields. I added a new variable and some new code to account for that variable. Now, for some reason, I can getting a "Sub or Function not defined" error on the code below.

Code:
wsName = Format(Date, "mmddyy")
If WorksheetExists(wsName) Then
    temp = Left(wsName, 6)
    i = 1
    wsName = temp & "_" & i
    Do While WorksheetExists(wsName)
        i = i + 1
        wsName = temp & "_" & i
    Loop
End If

The error is highlighting "WorksheetExists" and I can't seem to understand why. I've compared the full code to code from the previous version and there is no differences.

Here is the full code:
Code:
Sub Welcome_Call_Initiated()
Dim LastRow As Long
Dim Rng As Range, str1 As String, str2 As String, strx As String, str3 As String, str4 As String
Dim i As Long, wsName As String, temp As String
Dim arrResults
Dim b As Long
Application.ScreenUpdating = False
With Sheets("Combined")
    LastRow = .Cells(Rows.Count, 1).End(xlUp).Row
    Set Rng = .Range("A1:ET" & LastRow)
End With
With Sheets("Search Form")
    str1 = .Range("E8").Text
    str2 = .Range("E12").Text
    str3 = .Range("E16").Text
    str4 = .Range("E20").Text
End With
Sheets.Add After:=Sheets("Search Form")
ActiveSheet.Name = ("Results")
Sheets("Combined").Select
ActiveSheet.AutoFilterMode = False
Rng.AutoFilter Field:=96, Criteria1:=Array("Initiated"), Operator:=xlFilterValues
If y > 0 Then Rng.AutoFilter Field:=16, Criteria1:=(arrResults), Operator:=xlFilterValues
    If Not str1 = "" Then Rng.AutoFilter Field:=4, Criteria1:=str1
    If Not str2 = "" Then Rng.AutoFilter Field:=5, Criteria1:=str2
    If Not str3 = "" Then Rng.AutoFilter Field:=149, Criteria1:=str3
    If Not str4 = "" Then Rng.AutoFilter Field:=150, Criteria1:=str4
Rng.SpecialCells(xlCellTypeVisible).EntireRow.Copy Sheets("Results").Range("A1")
Application.CutCopyMode = False
Selection.AutoFilter
Sheets("Results").Activate
ActiveSheet.Columns.AutoFit
Rows("1:1").Select
    Selection.Find(What:="Current Comment", After:=ActiveCell, LookIn:= _
        xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False).Activate
    ActiveCell.EntireColumn.Select
    Selection.ColumnWidth = 40
Sheets("Results").Activate
Columns("CU:ER").Delete
Columns("Z:CQ").Delete
Sheets("Results").Activate
wsName = Format(Date, "mmddyy")
If WorksheetExists(wsName) Then
    temp = Left(wsName, 6)
    i = 1
    wsName = temp & "_" & i
    Do While WorksheetExists(wsName)
        i = i + 1
        wsName = temp & "_" & i
    Loop
End If
ActiveSheet.Name = wsName
Range("A1").Select
End Sub

Bill
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Where is the VBA code for the WorksheetExists UDF it is looking for?
It is trying to call a User Defined Function by that name, but it appears that it cannot be found in your VBA.
 
Upvote 0
The Erroring line expects there to be a WorksheetExists function somewhere in your project. It would be separate from the Welcome_Call_Intiated sub.

I suspect that you deleted the function, perhaps even deleted the module in which it was.

Just guessing from the name of the procedure, I would guess that your original code was something like


Code:
Function WorksheetExists(NameOfSheet as String) As Boolean
    On Error Resume Next
    WorksheetExits = (LCase(WorkSheets(NameOfSheet).Name) = LCase(NameOfSheet))
    On Error Goto 0
End Function
 
Upvote 0
Thanks everyone! I was cleaning out some of the unused macros to help shrink the sheet a bit and, I'm assuming, in my haste to clean I wiped the function.

Mike - thank you for adding this code back in. That would have been my next question.

Have a great day, guys!

Bill
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,694
Members
448,979
Latest member
DET4492

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