Przejdź do głównej zawartości

Jak sortować dane w wielu arkuszach jednocześnie?

W programie Excel możemy szybko i łatwo sortować dane w arkuszu na podstawie określonej kolumny, ale czy kiedykolwiek próbowałeś posortować dane w wielu arkuszach? Sortowanie ich jeden po drugim będzie czasochłonne, w tym artykule przedstawię łatwy sposób rozwiązania tego problemu.

Sortuj dane w wielu arkuszach jednocześnie za pomocą kodu VBA


strzałka niebieski prawy bąbelek Sortuj dane w wielu arkuszach jednocześnie za pomocą kodu VBA

Aby posortować dane na podstawie jednej kolumny we wszystkich arkuszach skoroszytu, może Ci pomóc poniższy kod VBA.

1. Przytrzymaj ALT + F11 klawisze, aby otworzyć Microsoft Visual Basic for Applications okno.

2. Kliknij wstawka > Modułi wklej następujący kod w Moduł Okno.

Kod VBA: Sortuj dane w wielu arkuszach jednocześnie:

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. Następnie naciśnij F5 Aby uruchomić ten kod, wszystkie arkusze, które mają to samo formatowanie, zostały posortowane naraz na podstawie kolumny E każdego arkusza w porządku malejącym.

Note: W powyższym kodzie, Odp .: F to zakres danych, który chcesz posortować, E to litera kolumny, według której chcesz sortować.

Najlepsze narzędzia biurowe

🤖 Pomocnik AI Kutools: Zrewolucjonizuj analizę danych w oparciu o: Inteligentne wykonanie   |  Wygeneruj kod  |  Twórz niestandardowe formuły  |  Analizuj dane i generuj wykresy  |  Wywołaj funkcje Kutools...
Popularne funkcje: Znajdź, wyróżnij lub zidentyfikuj duplikaty   |  Usuń puste wiersze   |  Łącz kolumny lub komórki bez utraty danych   |   Okrągły bez wzoru ...
Super wyszukiwanie: Wiele kryteriów VLookup    Wiele wartości VLookup  |   Przeglądanie pionowe na wielu arkuszach   |   Wyszukiwanie rozmyte ....
Zaawansowana lista rozwijana: Szybko twórz listę rozwijaną   |  Zależna lista rozwijana   |  Lista rozwijana wielokrotnego wyboru ....
Menedżer kolumn: Dodaj określoną liczbę kolumn  |  Przesuń kolumny  |  Przełącz stan widoczności ukrytych kolumn  |  Porównaj zakresy i kolumny ...
Polecane funkcje: Fokus siatki   |  Widok projektu   |   Duży pasek formuły    Menedżer skoroszytów i arkuszy   |  Biblioteka zasobów (Automatyczny tekst)   |  Selektor dat   |  Połącz arkusze   |  Szyfruj/odszyfruj komórki    Wysyłaj e-maile według listy   |  Super filtr   |   Specjalny filtr (filtruj pogrubienie/kursywa/przekreślenie...) ...
15 najlepszych zestawów narzędzi12 Tekst Tools (Dodaj tekst, Usuń znaki, ...)   |   50 + Wykres rodzaje (Wykres Gantta, ...)   |   40+ Praktyczne Wzory (Oblicz wiek na podstawie urodzin, ...)   |   19 Wprowadzenie Tools (Wstaw kod QR, Wstaw obraz ze ścieżki, ...)   |   12 Konwersja Tools (Liczby na słowa, Przeliczanie walut, ...)   |   7 Połącz i podziel Tools (Zaawansowane wiersze łączenia, Podział komórki, ...)   |   ... i więcej

Zwiększ swoje umiejętności Excela dzięki Kutools for Excel i doświadcz wydajności jak nigdy dotąd. Kutools dla programu Excel oferuje ponad 300 zaawansowanych funkcji zwiększających produktywność i oszczędzających czas.  Kliknij tutaj, aby uzyskać funkcję, której najbardziej potrzebujesz...

Opis


Karta Office wprowadza interfejs z zakładkami do pakietu Office i znacznie ułatwia pracę

  • Włącz edycję i czytanie na kartach w programach Word, Excel, PowerPoint, Publisher, Access, Visio i Project.
  • Otwieraj i twórz wiele dokumentów w nowych kartach tego samego okna, a nie w nowych oknach.
  • Zwiększa produktywność o 50% i redukuje setki kliknięć myszką każdego dnia!
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