Checking existence of a name

Reuben13

New Member
Joined
Mar 31, 2020
Messages
1
Office Version
  1. 2019
Platform
  1. Windows
Hi all,

This code is from "Microsoft Excel 2019 VBA and Macros" book. I just have a query about how the function actually searches for the name in the workbook. Is the statement in bold within the if....then used to search for the FindName? How does this part determine a names existence?

Appreciate any help

Function NameExists(ByVal FindName As String, _
Optional TargetBook As Workbook) As Boolean

If TargetBook Is Nothing Then
If ActiveWorkbook Is Nothing Then
NameExists = False
Exit Function
End If
Set TargetBook = ActiveWorkbook
End If

On Error Resume Next
NameExists = CBool(Len(TargetBook.Names(FindName).Name) <> 0)
On Error GoTo 0

End Function
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
The statement in bold does not search for the name. If the section in bold is true, then NameExists is set to false & the function exits. The next two lines after the bold section.
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,376
Members
449,080
Latest member
Armadillos

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