VBA Command to retrieve Column Name

AlInVegas2

New Member
Joined
Jun 19, 2019
Messages
27
I'm trying to find a command that will determine if the column of the current ActiveCell has a Defined Name. Is there a VBA command that does this? If so and a defined name is not found, what value is returned?
 
try this code:
VBA Code:
Sub test()
Dim col As Range, nam As Name, hasName As String
Set col = ActiveCell.EntireColumn
For Each nam In ActiveWorkbook.Names
    If Not Intersect(col, nam.RefersToRange) Is Nothing Then
        hasName = " column has name: " & nam
    Else
        hasName = "column does not have any name."
    End If
Next
MsgBox hasName
End Sub
 
Upvote 0
Solution
try this code:
VBA Code:
Sub test()
Dim col As Range, nam As Name, hasName As String
Set col = ActiveCell.EntireColumn
For Each nam In ActiveWorkbook.Names
    If Not Intersect(col, nam.RefersToRange) Is Nothing Then
        hasName = " column has name: " & nam
    Else
        hasName = "column does not have any name."
    End If
Next
MsgBox hasName
End Sub
Thanks. I went with an Error Resume Next method, setting a variable flag when the specific name couldn't be found. I'll play with this for another name search project I have.
 
Upvote 0

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