+ Reply to Thread
Results 1 to 5 of 5

Sort Data automatically using vba

Hybrid View

  1. #1
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,080

    Post Sort Data automatically using vba

    i have a range sheet.name("tota").rangeb4:b53

    i want when i put some data in this range then it go auto sort "a to z"

    thanx
    when i go to that sheet
    Use Code-Tags for showing your code :
    Please mark your question Solved if there has been offered a solution that works fine for you
    If You like solutions provided by anyone, feel free to add reputation using STAR *

  2. #2
    Registered User
    Join Date
    11-01-2012
    Location
    Cairo, Egypt
    MS-Off Ver
    MS Office 2013
    Posts
    76

    Re: Sort Data automatically using vba

    Try this:-

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim lCell As String
        lCell = ActiveWorkbook.Worksheets("tota").Range("B" & Rows.Count).End(3).Offset(1).Address
        ActiveWorkbook.Worksheets("tota").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("tota").Sort.SortFields.Add Key:=Range("B4"), _
            SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("tota").Sort
            .SetRange Range("B4:B53")
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        ActiveWorkbook.Worksheets("tota").Range(lCell).Select
    End Sub
    

  3. #3
    Registered User
    Join Date
    12-05-2016
    Location
    Switzerland
    MS-Off Ver
    2010
    Posts
    7

    Re: Sort Data automatically using vba

    This would be a litte bit shorter

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not IsEmpty(Cells(Target.Row, 1)) And Not IsEmpty(Cells(Target.Row, 2)) Then 'this makes sure the sort only happens if A and B have a value comment out if you dont need that
        Columns("A:B").Sort key1:=Range("A:A"), order1:=xlAscending, key2:=Range("B:B"), order2:=xlAscending, Header:=xlYes 'sorts A and B ascending by A then B
    End If' this has to be commented out too if you remove the if 
    End Sub
    Last edited by TheAnalyticalWolf; 12-06-2016 at 12:25 PM.

  4. #4
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,080

    Re: Sort Data automatically using vba

    Thanx all of u dear

  5. #5
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,080

    Re: Sort Data automatically using vba

    i have a question?

    if i sort out automatically data from different sheets at a time

    thanx

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Sort Data Automatically
    By mye_witch in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-24-2016, 05:31 AM
  2. How can i automatically sort data
    By Losguapos1 in forum Excel General
    Replies: 1
    Last Post: 10-10-2013, 08:36 AM
  3. Using VBA Code to sort my data automatically
    By ssincerely in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-10-2013, 02:12 PM
  4. [SOLVED] Automatically sort the data and ranking based on the sorted data
    By rakesh2806 in forum Excel General
    Replies: 6
    Last Post: 01-07-2013, 03:51 PM
  5. sort data automatically
    By verisme in forum Excel General
    Replies: 5
    Last Post: 12-27-2009, 04:53 AM
  6. automatically Data sort
    By s.w in forum Excel General
    Replies: 1
    Last Post: 11-14-2007, 10:42 AM
  7. Sort Data Automatically
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-13-2005, 01:05 PM

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