Excel For Mac Vba To Sort A Column

Автор:

Exclusive to Studio Artist. New in Studio Artist 5 is Vector Paints. Vector Paints not only simulate natural media paints from oils to chalks but also create completely new vector paint looks previously not possible. Vector Paints can be found in the Paint Synthesizer as well as in the Vectorizer. They can be applied automatically or manually. Studio artist 5 for mac.

I rarely have a header row and want to simply select the range (usually 4-5 columns and anywhere from 5 to 30 rows) and use the a-z (or z-a) button to sort against the 1st column. Now for the problem – more than half of the time, excel assumes that the first row is a header row and will not sort it with the rest.

How to auto sort column by value in Excel?

For example, you have a purchase table as left screen shot shown. Now you want the Price column to be sorted automatically when you enter new number/price in this column, how could you solve it? Here I introduce a VBA macro to help you auto sort a specific column by value in Excel.

Auto sort column by value with VBA

Easily sort by frequency of occurrences in Excel

Kutools for Excel's Advanced Sort utility supports sorting data by text length, last name, absolute value, frequency, etc. in Excel quickly. Full Feature Free Trial 30-day!

Office Tab Enable Tabbed Editing and Browsing in Office, and Make Your Work Much Easier..
Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%
  • Reuse Anything: Add the most used or complex formulas, charts and anything else to your favorites, and quickly reuse them in the future.
  • More than 20 text features: Extract Number from Text String; Extract or Remove Part of Texts; Convert Numbers and Currencies to English Words.
  • Merge Tools: Multiple Workbooks and Sheets into One; Merge Multiple Cells/Rows/Columns Without Losing Data; Merge Duplicate Rows and Sum.
  • Split Tools: Split Data into Multiple Sheets Based on Value; One Workbook to Multiple Excel, PDF or CSV Files; One Column to Multiple Columns.
  • Paste Skipping Hidden/Filtered Rows; Count And Sum by Background Color; Send Personalized Emails to Multiple Recipients in Bulk.
  • Super Filter: Create advanced filter schemes and apply to any sheets; Sort by week, day, frequency and more; Filter by bold, formulas, comment..
  • More than 300 powerful features; Works with Office 2007-2019 and 365; Supports all languages; Easy deploying in your enterprise or organization.

Auto sort column by value with VBA

This VBA macro will sort all data in a specific column automatically as soon as you enter new data or change value in the column in Excel.

Columns in the current view are identified with a check mark. Tips:.In the item list, you can click on a column heading to sort by that column.To rearrange the columns, click a column heading, and then drag it to a new position.To resize a column, rest the pointer on the right edge of the column header until the pointer changes, and then drag the edge.Customize the reading paneThe reading pane, sometimes called the preview pane, lets you read items without opening them. Outlook mac see folder for email. By default, the item list is displayed vertically between the navigation pane and the reading pane. The available columns vary, depending on the type of items in the list.On the Organize tab, click Reading Pane, and then make sure that Below or Hidden is selected.On the View menu, select to Columns, and then choose a column name. Note: The item list is not available for Calendar view.Change the text size for the item list.On the Outlook menu, choose Preferences.Under Personal Settings, choose Fonts.Under Text display size, slide the selector to the desired font size.Change the sort order in the item list.On the Organize tab, select Arrange By, and then choose an option.Choose columns for the item listIf the reading pane is hidden or positioned below the item list, you can choose the columns you want for the item list.

1. Right click current sheet name in the Sheet Tab bar, and then click the View Code from the right-clicking menu.

2. In the opening Microsoft Visual Basic for Application dialog box, paste the following VBA macro code into the opening window.

VBA: Auto Sort Column in Excel

Note: In the above vba code, B:B means it will auto sort Column B, B1 is the first cell in Column B, B2 is the second cell in Column B, and you can change them based on your needs.

3. Then go back to the worksheet, when you enter a new number in the Price column or modify any existing prices, the Price column will be automatically sorted in ascending order.
Note: when entering new number in the Price column, you must enter the number in the first blank cell below original numbers. If there are blank cells between new entered number and original numbers as well as blank cells between original numbers, this column won't be sorted automatically.

Demo: Auto sort column by value with VBA in Excel

Kutools for Excel includes more than 300 handy tools for Excel, free to try without limitation in 30 days. Download and Free Trial Now!

The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails..
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range..
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns.. Prevent Duplicate Cells; Compare Ranges..
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select..
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more..
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments..
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic..
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF..
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
or post as a guest, but your post won't be published automatically.
Loading comment.. The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Hi, it arrange the entire row but I have some link on cells into specific folder which is left behind after sort.
  • To post as a guest, your comment is unpublished.
    This has been really helpful but I have 2 rows of headers (rows 1 and 2) and when I run the VBA it takes the second row to the bottom of the dates
    how do I stop this?
    • To post as a guest, your comment is unpublished.
      Hi kerry,
      There is a VBA that will automatically sort cells in the Column igonring the first two header cells.
      Private Sub Worksheet_Change(ByVal Target As Range)
      Dim xIntRC As Integer
      Dim xURg As Range
      On Error Resume Next
      If Not Intersect(Target, Range('B:B')) Is Nothing Then
      If Not Intersect(Target, Range('B1:B2')) Is Nothing Then Exit Sub
      Set xURg = ActiveSheet.UsedRange
      xIntRC = xURg.Rows.count
      Range('B2:B' & xIntRC).Sort Key1:=Range('B3'), _
      Order1:=xlAscending, Header:=xlYes, _
      OrderCustom:=1, MatchCase:=False, _
      Orientation:=xlTopToBottom
      End If
      End Sub
  • To post as a guest, your comment is unpublished.
    May I ask if there is a way to use this VBA code if there is a formula in the column that you want to be the main sort.
    i.e. if A2 = the sum of f2 + g2+ h2 and column A needs to be sorted on the total sum? (I can't get VBA to work if formula in the cells)
    Any assistance would be kindly appreciated as hope to use it for ranking races when the winner is the one with the total of three racing events.
    Thank You
    • To post as a guest, your comment is unpublished.
      i also want to know solution for Paula problem. please share
  • To post as a guest, your comment is unpublished.
    Hi,
    How can I make this macro start after I fill all data to the specific column?
    I want the listing macro start after I fill empty boxes. Because when I use this, it changes the place suddenly.
    I need to start this macro after I filled the last data of that column (20 datas to be exact)
  • To post as a guest, your comment is unpublished.
    Hello, I am an intermediate Excel user. I am wondering if someone could help direct me for what I am trying to accomplish. Here is what I am trying to do: Auto-Sort with Custom Order.
    A little about my spreadsheets: I have one sheet (named: Sheet1) that lists 16 columns (A through P) and currently 19 rows (this number will increase as more data is entered). In the last column (column P) all cells have a drop down menu of options (located and pulled from sheet two (named 'BackEnd'). The drop down selections are color-coded (using conditional formatting rules).
    What I am hoping to do: As a user enters data in a new row, as soon as they are finished selecting an option from the drop down menu in column P, Excel will auto-sort the new row to a specific order. I have been able to create VBA code for auto-sorting in ascending and descending order, but I have not been able to create a code for auto-sorting the data in a specific order. The order I would like to have the data sorted into is:
    Unresponsive
    Not Interested
    Interested
    Pre-Screened Not Qualified:
    Pre-Screened Qualified
    Application Pending
    Application Approved
    Initial Assessment:
    Scope of Work:
    Home Repairs in Progress
    On Hold:
    Complete
    Other:
    Is this possible? Any help is appreciated! Thank you!
  • To post as a guest, your comment is unpublished.
    While this is a fantastic code, I would like to know if anyone could help me get it go from ascending to descending? In other words, I'm looking for it to be the largest number on top with the lowest number on the bottom
    • To post as a guest, your comment is unpublished.
      Change (Order1:=xlAscending, Header:=xlYes, ) To (Order1:=xlDescending, Header:=xlYes, )
  • To post as a guest, your comment is unpublished.
    Any one know how to set set an auto serial no. for an excel work sheet. The number should excludes all heading and sub headings, and should auto re arrange after adding or deleting a row.
    • To post as a guest, your comment is unpublished.
      Hi,
      Kutools for Excel provides an Insert Sequence Number feature, which can insert unique and consecutive values no matter how many times you insert.
      For example, the first time you insert 1,2,3,4;
      The second time this feature will insert 5,6,7,8,9,10
      The third time this feature will insert 11,12,…
  • To post as a guest, your comment is unpublished.
    Thanks for code and logic. The above logic is not working when we are looking at bigger range of cells like Intersect(Target, Range('B:B,C:C,D:D')). I want if there is change in any cell in the Column (B,C or D), resorting needs to be done.
  • To post as a guest, your comment is unpublished.
    THANK YOU!!!
  • To post as a guest, your comment is unpublished.
    Copied the code exactly into my sheet in VBA. But nothing is happening am I missing something? Did exactly what you did.
  • To post as a guest, your comment is unpublished.
    First row is excluded for the sorting
    • To post as a guest, your comment is unpublished.
      I had the same problem and I found out why. Go to line 5, (Order1:=xlAscending, Header:=xlYes, _). The script is telling Excel the first cell is a header, and therefore it will ignore it when the sorting takes place. If you want to include the first row, change it to the following line:
      Order1:=xlAscending, Header:=xlNo, _
  • To post as a guest, your comment is unpublished.
    Hello. Excellent trick, thank you very much. In my file, I have important info which I need to see in cells A1 and A2. Therefore, I have stabilized all cells and my values start from A3 to A500. When I execute this vba, my info in cell A2 goes in cell 501. How can I make it start ranging form cell A3? Thank you in advance!
  • To post as a guest, your comment is unpublished.
    Say I need to auto sort column 'C' and column 'D'. How would I modify the code to sort both columns?
  • To post as a guest, your comment is unpublished.
    This is GREAT. This was of great help.
  • To post as a guest, your comment is unpublished.
    I am looking for the same automatic sorting when entering data for my excel chart. Finding it hard to understand the details of what you have entered here as example. I would really appreciate it if someone here who did the example above could help me sort my sheet out so it did the same. I have a F1 chart that shows winners, and points, and would like it so that when the points are entered next to the drivers name for a specific race for the total on the right hand side of the sheet to be in numerical order, WITHOUT MIXING THE RESULT against other drivers. It seems that I can not place on this message an attachment of my chart so if you are able to alter my chart for me so this will happen I would like to hear from you. I can send it via email to you. If you can help with this then please email me at lordmarshall2013@gmail.com and in the SUBJECT line please write F1 Excel help and will reply with the chart attached for you. Thanks in advance for any help you can provide.
  • To post as a guest, your comment is unpublished.
    Beautiful, beautiful, beautiful, thank you SO much. Would have never been able to figure this out on my own and I really appreciate you sharing this!!!
To compare two lists and extract common values, you can use a formula based on the FILTER and COUNTIF functions. In the example shown, the formula in F5 is:=FILTER(list1,COUNTIF(list2,list1))where list1 (B5:B15)..
To sort values by columns, you can use the SORT function. In the example shown, data is sorted by the Group column. The formula in C8 is:=SORT(C4:L5,2,-1,TRUE)The result is the range C4:L5 sorted by score in..
To sort by one column, you can use the SORT function or SORTBY function. In the example shown, data is sorted by the Group column. The formula in F5 is:=SORT(B5:D14,3)Notice data is sorted in ascending order (A-Z)..