Alphabetical Order

  • Hello everyone

    I found the vba code to alphabetize the table, I type in "command button" but it is not working.


    Code
    Sub Sort_A()
        With Sheets("Viaggio")
            .Range("A2:A1027").Sort Key1:=.Range("A2"), Order1:=xlAscending, Header:=xlNo, _
            OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
        End With
    End Sub

    or is there an automatic vba macro that can do this?

    Let it sort alphabetically as data is added.

  • Hello,


    If we assume your Database is located in Sheet2, you can test following macro :

    Code
    Sub SortTable2()
    Dim rng As Range
    Set rng = Sheet2.Range("A1").CurrentRegion
    rng.Sort [A1], xlAscending, Header:=xlYes
    End Sub

    Hope this will help :)

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

    Edited once, last by Carim ().

  • Merhaba,


    Verilerinizin Sayfa2'de kullanılacağı varsayarsak, aşağıdaki makroyu test edebilirsiniz:

    Code
    Alt SıralamaTable2()
    Aralık Olarak Karart
    Set rng = Sheet2.Range("A1").CurrentRegion
    rng.Sırala [A1], xlArtan, Başlık:=xlEvet
    Aboneliği Sonlandır

    İnşallah bu yardımcı olur:)

    işe yarıyor teşekkürler :başparmak yukarı: :başparmak yukarı :thumbup: :thumbup: :thumbup: :thumbup:  <3 <3


    so can i run this macro automatically?

    For example, can this macro run after saying add with userform? or can i add it to "commandbutton" button?

    This macro does not sort the existing data, I add new data, it sorts the old data, not the old data

    Edited 2 times, last by ozex11 ().

  • In order to run the macro automatically, you can insert at the end of your previous macro this instruction

    Code
    Application.Run("SortTable2")


    This macro will sort the entire table (Old and New Data) starting from cell A1 down to last row and to last column

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • In order to visually understand what is exactly the CurrentRegion in the macro ...

    see images in link below :

    VBA Current Region - Automate Excel
    In this ArticleCurrentRegion SyntaxObtain the Current RegionCounting the Rows and Columns in the Current RegionClearing the Current RegionAssigning the Current…
    www.automateexcel.com

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Makroyu otomatik olarak çalıştırmak için, önceki makronuzun sonuna bu komutu ekleyebilirsiniz.

    Code
    Application.Run("SortTable2")


    Bu makro, A1 hücresinden başlayarak son satıra ve son sütuna kadar tüm tabloyu (Eski ve Yeni Veriler) sıralar.


    i do it this way but i get an error message called 400 where am i doing wrong

    and it doesn't sort the data in a1, it starts from a2

    Edited once, last by Carim ().

  • Since I cannot see your code and guess what is wrong, the best thing to do is to attach your Excel file with your next message ...

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Thank you for the sample file ..

    Since you have no Headers (titles are usually in Row 1)

    You can test :

    Code
    Sub SortTable2()
    Dim rng As Range
    Set rng = Sayfa2.Range("A1").CurrentRegion
    rng.Sort [A1], xlAscending
    End Sub

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • What do you mean exactly when you say : run the macro automatically ?

    Do you input your data manually from Column A to Column C ?

    Do you want the macro to run as soon as you have finished your input for each row ?

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Makroyu otomatik olarak çalıştır derken tam olarak ne demek istiyorsunuz?

    Verilerinizi Sütun A'dan Sütun C'ye manuel olarak mı giriyorsunuz?

    Her satır için girişinizi bitirir bitirmez makronun çalışmasını istiyor musunuz?

    When I save data to this table with the "userform" you made, I want the added data to be sorted automatically.


    When I enter data with both "manually" and "userform" it would be better to have it sorted automatically.

  • OK ...


    First for the UserForm, you will need to replace the current version with the following :

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • OK ...


    First for the UserForm, you will need to replace the current version with the following :

    I did what you said but I get an error

    Can you review the file?

  • Thank you for your very kind comments :)

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Concerning the Manual input ... could you explain how do you plan to do it ?

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • OK...


    You also want to enter data "manually" or directly in Sheet2 ...


    How ...?

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!