Unable to run a macro to sort out data on different worksheets saved on a single workbook

Makwa

New Member
Joined
Mar 6, 2023
Messages
3
Office Version
  1. 365
  2. 2021
  3. 2013
Platform
  1. Windows
The problem here is to get the macro to automatically run this procedure on different spreadsheet ,how do I get the macro to also run this sort code/procedure without my interference?

The problem here is after sorting the data(adding headers, columns and separating text to numbers)i now want to sort the entire worksheet by "sales unit this year" then move to the last ACTIVE cell, then got to the next empty cell then put in that column and assign it to the data in column F then populate the data to the last cell that has data .

i use a for loop to move through deferent worksheets in this workbook the code must be able to accommodate the dynamic number of worksheets and data on each worksheet




please see below
 

Attachments

  • data comes like this.png
    data comes like this.png
    17.1 KB · Views: 6
  • how i use sort method to move data into one column.png
    how i use sort method to move data into one column.png
    78.2 KB · Views: 8
  • how data must be.png
    how data must be.png
    17.4 KB · Views: 6
  • i use an equal formula to bring the remainder of the data to column E.png
    i use an equal formula to bring the remainder of the data to column E.png
    14.8 KB · Views: 7
  • macro error 1.png
    macro error 1.png
    47.7 KB · Views: 7
  • macro error 2.png
    macro error 2.png
    75.8 KB · Views: 4
  • the code with two procedures .png
    the code with two procedures .png
    125.2 KB · Views: 7

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I understand that you tried to describe the issue/need but unfortunately, it is not totally clear to me. Maybe try to describe the need again, differently.

The pictures are only somewhat helpful.

First try posting your VBA code in a post. Someone may be able to tell you how to modify it. To do that use the "quick wrap" at the top of the post that says VBA. "Wrap" your code within the start and end labels. Example:

VBA Code:
Sub DoSort(pwsSortSheet As Worksheet, psKeyHeaderName As String, pvDirection As Variant)
    
    Dim rAllData As Range
    
    With pwsSortSheet
        
        Set rAllData = .Range(psKeyHeaderName).CurrentRegion
        
        With .Sort
        
            .Header = xlYes
            
            .SortFields.Clear
            
            .SortFields.Add Key:=Range(psKeyHeaderName), Order:=pvDirection
            
            .SetRange rAllData
            
            .Apply
        
        End With '.Sort
        
    End With

End Sub

Use the Preview button (upper right for a post) to see if the code looks like it does in the VBA editor. Add comments to the code so the helper understands what you are trying to do.

Also, try using Mr Excel's excellent XL2BB add-in to post portions of your worksheets. See here: Link to Add-in

If possible use dropbox or 1drive to post a link to any workbooks that you can share. Otherwise 1) helpers have to guess what is in them and 2) helpers have to manufacture "fake" data to work with. Making such fake data can take a lot of work for the helper.

I hope that this was helpful.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top