Hoppa till huvudinnehåll

Hur sorterar jag data på flera kalkylblad samtidigt?

I Excel kan vi sortera data i ett kalkylblad baserat på en specifik kolumn snabbt och enkelt, men har du någonsin försökt sortera data över flera kalkylblad? Att sortera dem en efter en kommer att vara tidskrävande, den här artikeln kommer jag att introducera ett enkelt sätt att lösa det.

Sortera data på flera kalkylblad samtidigt med VBA-kod


pil blå höger bubbla Sortera data på flera kalkylblad samtidigt med VBA-kod

För att sortera data baserat på en kolumn i alla ark i din arbetsbok kan följande VBA-kod hjälpa dig.

1. Håll ner ALT + F11 nycklar för att öppna Microsoft Visual Basic för applikationer fönster.

2. Klicka Insert > Modulernaoch klistra in följande kod i Modulerna Fönster.

VBA-kod: Sortera data på flera kalkylblad samtidigt:

Sub SortAllSheets()
   'Updateby Extendoffice
   Dim WS      As Worksheet
   ActiveSheet.Range("a1:f1").Select
   Selection.Copy
   On Error Resume Next
   Application.ScreenUpdating = False
   For Each WS In Worksheets
      WS.Columns("A:F").Sort Key1:=WS.Columns("E"), Order1:=xlDescending
   Next WS
   ActiveSheet.Range("A1").PasteSpecial Paste:=xlPasteAll
   Application.ScreenUpdating = True
End Sub

3. Tryck sedan på F5 för att köra den här koden, har alla ark som har samma formatering sorterats baserat på kolumn E på varje ark i fallande ordning samtidigt.

Anmärkningar: I ovanstående kod, A: F är dataintervallet som du vill sortera, E är kolumnbokstaven som du vill sortera utifrån.

Bästa kontorsproduktivitetsverktyg

🤖 Kutools AI Aide: Revolutionera dataanalys baserat på: Intelligent utförande   |  Generera kod  |  Skapa anpassade formler  |  Analysera data och generera diagram  |  Anropa Kutools funktioner.
Populära funktioner: Hitta, markera eller identifiera dubbletter   |  Ta bort tomma rader   |  Kombinera kolumner eller celler utan att förlora data   |   Rund utan formel ...
Superuppslag: Flera kriterier VLookup    VLookup med flera värden  |   VSök över flera ark   |   Fuzzy Lookup ....
Avancerad rullgardinslista: Skapa snabbt en rullgardinslista   |  Beroende rullgardinslista   |  Flervals-rullgardinslista ....
Kolumnhanterare: Lägg till ett specifikt antal kolumner  |  Flytta kolumner  |  Växla synlighetsstatus för dolda kolumner  |  Jämför intervall och kolumner ...
Utvalda funktioner: Rutnätsfokus   |  Designvy   |   Stor formelbar    Arbetsbok & Bladhanterare   |  Resursbibliotek (Automatisk text)   |  Datumväljare   |  Kombinera arbetsblad   |  Kryptera/Dekryptera celler    Skicka e-postmeddelanden efter lista   |  Superfilter   |   Specialfilter (filtrera fet/kursiv/genomstruken...) ...
Topp 15 verktygssatser12 text verktyg (lägga till text, Ta bort tecken, ...)   |   50+ Diagram Typer (Gantt Chart, ...)   |   40+ Praktiskt Formler (Beräkna ålder baserat på födelsedag, ...)   |   19 Införande verktyg (Infoga QR-kod, Infoga bild från sökväg, ...)   |   12 Konvertering verktyg (Siffror till ord, Valutaväxling, ...)   |   7 Slå ihop och dela verktyg (Avancerade kombinera rader, Dela celler, ...)   |   ... och mer

Uppgradera dina Excel-färdigheter med Kutools för Excel och upplev effektivitet som aldrig förr. Kutools för Excel erbjuder över 300 avancerade funktioner för att öka produktiviteten och spara tid.  Klicka här för att få den funktion du behöver mest...

Beskrivning


Fliken Office ger ett flikgränssnitt till Office och gör ditt arbete mycket enklare

  • Aktivera flikredigering och läsning i Word, Excel, PowerPoint, Publisher, Access, Visio och Project.
  • Öppna och skapa flera dokument i nya flikar i samma fönster, snarare än i nya fönster.
  • Ökar din produktivitet med 50 % och minskar hundratals musklick för dig varje dag!
Comments (11)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
This didn't seem to work for me. I have a workbook with 12 sheets ordered by months of the year each sheet containing corresponding data regarding companies products etc. My objective is to sort and filter the all the sheets in the workbook. I would like to have one sheet that would act as the parent sheet (e.g. first month of the year), which I would perform a filter or sort function on (e.g. A -> Z sort) and automatically have the other sheets follow the same sort or filter. For example, when using the sheet labeled "January" if for example I choose column "D" which includes the days in the month which I want in "ascending" order - when actualizing the A -> Z sort on the "January" sheet, I want this to effect the rest of all the sheets in the sequence (Feb-Dec) with all days of the month sorted A -> Z. Any change made on the "January" sheet as it relates to sorting and filtering, should effect the balance of the sheets in the workbook.
This comment was minimized by the moderator on the site
Can you run this without including all sheets? I.e. leave some sheets out of the macro?
This comment was minimized by the moderator on the site
i want to split the data in multiple work books and then add the value in one of the column..

i have prepared the code to split the data in workbooks.. but need help on adding the total in one of the column
This comment was minimized by the moderator on the site
works well but how can I avoid including the headings (ie row 1?)
This comment was minimized by the moderator on the site
Hello, Lucy,
To sort all sheets exclude the header row, please apply the below vba code:(Note: please change the cell references to your need)

Sub SortAllSheets()
'Updateby Extendoffice
Dim WS As Worksheet
Dim xIntR As Integer
ActiveSheet.Range("A1:F1").Select
On Error Resume Next
Application.ScreenUpdating = False
For Each WS In Worksheets
xIntR = Intersect(WS.UsedRange, WS.Range("A:F")).Rows.Count
WS.Range("A2:F" & xIntR).Sort Key1:=WS.Range("A2:A" & xIntR), Order1:=xlDescending
Next WS
Application.ScreenUpdating = True
End Sub

Please try, hope it can help you!
This comment was minimized by the moderator on the site
Hey this is great thank you so much for this! My only issue with this code is that it does not execute on my first sheet. It does execute on my remaining sheets. HOw would I get this to execute on all of the sheets? It's as if the code skips over the first sheet. Any help would be much appreciated :)
This comment was minimized by the moderator on the site
Very usefull code Thanks
This comment was minimized by the moderator on the site
In the hope that you see this...! This works wonderfully - but it includes cells with a formula but no data, creating gaps in the tabs and messing up the data on the rows. I need to keep those cells in my tabs as they look up names added to the 'master tab' I want it to only sort cells with an actual name - a quick fix???
This comment was minimized by the moderator on the site
worked like a charm for me...thank you!
This comment was minimized by the moderator on the site
Doesn't work...
This comment was minimized by the moderator on the site
How can I make this work for multiple columns. I am trying to sort some by the K column and some by the M column and I know the exact sheet numbers. My M column (when I use the above code) is only being sorted by the K, not by M, so therefore it is not working. 
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations