+ Reply to Thread
Results 1 to 4 of 4

VBA code for sorting

Hybrid View

  1. #1
    Registered User
    Join Date
    07-03-2007
    Posts
    26

    Arrow VBA code for sorting

    Hi i`ve been trying to create a VBA code for sorting the data in sheet1 but unfortunately it does not work. I have also tried to create a macro but didnt work also. Help is much appreaciated. Thank you in advance.

    Please see the attachement.


    tink_
    Attached Files Attached Files

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Your data won't sort with or without VBA. To use sort the data must be in a Table with no completely empty columns or rows. Then use the Macro Recorder to get your code.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    07-03-2007
    Posts
    26

    Smile

    hi roy. Thank you for the advice. So there is no way that i can sort the data in sheet1. Is there any way that i can sort them automatically through VBA code? Because every month 1row of data is added in sheet 1. I hope you can help me. Thank you in advance.


    tink_

  4. #4
    Forum Contributor
    Join Date
    07-05-2007
    Location
    Lexington, MA
    Posts
    302

    Range for sort is possibly incorrect

    Private Sub Worksheet_Change(ByVal Target As Range)
    rowcount = Cells(Cells.Rows.Count, "a").End(xlUp).Row
    'you can change the column here change from d to whatever
    
    Range("a1:" & "d" & rowcount).Select
    'you can change the sort column here change from d to whatever
    'you can change also if there is heater here form Header:=xlNo to Header:=xlYes
    
    -- Range selected is say "A1:D29"
    -- But your data actually occupies rows A6:D29 
    
    Selection.Sort Key1:=Range("C1"), Order1:=xlDescending, Header:=xlNo, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    
    -- This sort seems OK, but the data in Col C is constant in rows 6:29
    -- and blank in the header rows, so it may seem to sort incorrectly. 
    
    Range("a6").Select
    End Sub

+ 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