define name

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Selection.CurrentRegion.Select
Selection.CreateNames Top:=True, Left:=False, Bottom:=False, Right:=False

The above code define the names of the top colums in my selection - but it
does that for the wotksheet level - I will need to have that define locally
for the sheet only.

Any idea?

M
 
It doesn't look like there's an option that allows you to make the names local.

But you could do it with something like:

Option Explicit
Sub testme01()

Dim myRng As Range
Dim myCol As Range

Set myRng = Selection.CurrentRegion

For Each myCol In myRng.Columns
With myCol
.Resize(.Rows.Count - 1, 1).Offset(1, 0).Name _
= "'" & .Parent.Name & "'!" & .Cells(1).Value
End With
Next myCol

End Sub
 
Thank you
Option Explicit
Sub testme01()

Dim myRng As Range
Dim myCol As Range

Set myRng = Selection.CurrentRegion

For Each myCol In myRng.Columns
With myCol
.Resize(.Rows.Count - 1, 1).Offset(1, 0).Name _
= "'" & .Parent.Name & "'!" & .Cells(1).Value
End With
Next myCol

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top