• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Sort specific ranges across some spreadsheets keeping empty-zeros at bottom

buck20

New Member
I have a spreadsheet of 32 tabs, 26 of them are identical. I want a code to sort column “A” in those 26 identical tabs but specific ranges only:
Rows A22:A35
Rows A40:A53
Rows A58:A71

Expanding the sorting from column A to P, and this is what I have so far:

Code:
Sub UnproSortProct()

Dim ws As Worksheet
Dim sorigsheet As String
Dim sorigcell As String
Dim j As Integer
      
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    sorigsheet = ActiveSheet.Name
    sorigcell = ActiveCell.Address
    For Each ws In Worksheets
        ws.Select
        ws.Unprotect Password:="password"
    Next ws

     Sheets("sheet1").Activate
 
           Range("A22:p35").Sort key1:=Range("a22"), order1:=xlAscending, Header:=xlNo
           Range("A40:p53").Sort key1:=Range("a40"), order1:=xlAscending, Header:=xlNo
           Range("A58:p71").Sort key1:=Range("a58"), order1:=xlAscending, Header:=xlNo

    Sheets("sheet2").Activate

I’m repeating the sorting for every of the 26 sheets. The code is long. The problem is that is very slow and the cells on “A” column have formulas, so the sorting ends up with blank cells and zeros at the top. I’m looking an elegant way to sort in a more efficient manner, that doesn’t cause that much stress in the Excel workbook, and that the blank and zeros ends up at the bottom.

 
Last edited by a moderator:
Back
Top