how do I view excel rows in name order infirst column?

B

Buglebeek1

I want to view name labels in alphabetical order in that I label in the first
column. How can I adjust the column after I add new names?
 
H

Harlan Grove

Buglebeek1 said:
I want to view name labels in alphabetical order in that I label in
the first column. How can I adjust the column after I add new names?

You'd need to sort the entire table. You could use an event handler
macro, specifically, a Change event handler, to sort the table upon
any entry in the first column.

For example, with the table range identified by the sheet-level
defined name tbl, and assuming tbl contains headers in its first row,


Private Sub Worksheet_Change(ByVal Target As Range)
'put table range's name here - change as needed
Const NMDRNG As String = "tbl"

Dim t As Range, n As Long

Set t = Names(NMDRNG).RefersToRange
n = t.Columns.Count
Set t = t.Resize(t.End(xlDown).Row - t.Row, 1).Offset(1, 0)

'exit quickly if no change in 1st col of named range
If Intersect(Target, t) Is Nothing Then Exit Sub

On Error GoTo CleanUp
Application.EnableEvents = False

t.Resize(, n).Sort _
key1:=t.Cells(1, 1), _
Order1:=xlAscending, _
Header:=xlNo

CleanUp:
Application.EnableEvents = True
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

Top