+ Reply to Thread
Results 1 to 5 of 5

Sorting full table by name

Hybrid View

  1. #1
    Registered User
    Join Date
    04-18-2012
    Location
    hamburg, germany
    MS-Off Ver
    Excel 2003
    Posts
    6

    Sorting full table by name

    hi,
    i´m new to excel. i´ve created a table B16 to H25
    B=name C=adr D=city E=zip ... etc.
    when i insert a new name, i want to to automaticaly sort
    the table by the names.
    the following code only sorts B, the columns from C to H
    are untouched. what is wrong ?

    Private Sub worksheet_Change(ByVal Target As Range)
    On Error GoTo fehler
    Application.EnableEvents = False
        Range("B16:H25").Select
        ActiveWorkbook.Worksheets("Endstand").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Endstand").Sort.SortFields.Add Key:=Range("B16:B25"), _
            SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Endstand").Sort
            .SetRange Range("B15:H25")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    fehler:
    Application.EnableEvents = True
    End Sub
    thx and regards from germany
    thorsten
    Last edited by thorb; 04-19-2012 at 01:35 AM.

  2. #2
    Valued Forum Contributor marreco's Avatar
    Join Date
    07-02-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    1,862

    Re: Sorting full table by name

    Read the rules
    place the code between the tags
    "No xadrez nem sempre a menor dist?ncia entre dois pontos ? uma linha reta" G. Kasparov.

    If your problem is solved, please say so clearly, and mark your thread as Solved: Click the Edit button on your first post in the thread, Click Go Advanced, select b from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Edit button will not appear -- ask a moderator to mark it.

  3. #3
    Valued Forum Contributor marreco's Avatar
    Join Date
    07-02-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    1,862

    Re: Sorting full table by name

    Try..

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim lrow As Long
    lrow = Range("B" & Rows.Count).End(xlUp).Row
    If Range("H" & lrow).Value <> "" Then
        [B17:H25].Sort Key1:=[B16], Order1:=xlAscending
    End If
    End Sub

  4. #4
    Registered User
    Join Date
    04-18-2012
    Location
    hamburg, germany
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Sorting full table by name

    hi,
    thx, but it doesn´t work. i´ve inserted the code in the editor
    but it did nothing
    some rows or cells can be empty
    Last edited by thorb; 04-19-2012 at 01:37 AM.

  5. #5
    Registered User
    Join Date
    04-18-2012
    Location
    hamburg, germany
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Sorting full table by name

    nobody here who could help ?

    edit: problem solved :-)
    the following code does it
    Private Sub worksheet_Change(ByVal Target As Range)
    On Error GoTo fehler
    Application.EnableEvents = False
    With Worksheet
    If Target <> "" And Target.Row > 15 And Target.Row < 26 And Target.Column > 1 And Target.Column < 33 Then
    x1 = Selection.Row
    y1 = Selection.Column
     Range("B16:AF25").Sort Key1:=Range("B16"), Order1:=xlAscending, _
    	Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
    	Orientation:=xlTopToBottom
    Cells(x1, y1).Select
    End If
    End With
    fehler:
    Application.EnableEvents = True
    End Sub
    Last edited by thorb; 04-19-2012 at 08:59 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1