Sorry for the noob question but I would like to understand the code I just got here. I'd like to explain these to my stakeholders in layman's terms.
"On Error Resume Next"
- Does this mean that if the first worksheet gives an error (just do not show it) then test the next worksheets for errors (still, do not show them)? So can it be considered a looping statement somehow without the errors popping up?
"WorksheetExists = Not ws Is Nothing"
- So if a true is found, that is equivalent to 1, right? Zero is for false. So that will give us "Not 1 is nothing" or "not zero is nothing" so how can someone explain it to a non programmer like a priest or a English teacher?
Can "WorksheetExists = Not ws Is Nothing" be coded in a way that is friendlier to newbie programmers?
Complete Code:
Function WorksheetExists(sheet_name As String, Optional wb As Workbook) As Boolean
Dim ws As Worksheet
If wb Is Nothing Then Set wb = ThisWorkbook
On Error Resume Next
Set ws = wb.Sheets(sheet_name)
On Error GoTo 0
' If ws Is Nothing Then
' WorksheetExists = False
' Else
' WorksheetExists = True
' End If
'
WorksheetExists = Not ws Is Nothing
' is ws not nothing? Yes, it is something. Return TRUE.
' is ws not nothing? No, it is really nothing. Return FALSE.
End Function
Thank you.