Loncat ke daftar isi utama

Bagaimana cara menjalankan makro yang sama pada beberapa lembar kerja secara bersamaan di Excel?

Biasanya, kita dapat menjalankan makro di lembar kerja, jika ada beberapa lembar perlu menerapkan makro yang sama ini, Anda harus memicu kode satu per satu lembar. Jika ada cara cepat lain untuk menjalankan makro yang sama di beberapa lembar kerja sekaligus di Excel?

Jalankan atau jalankan makro yang sama di beberapa lembar kerja secara bersamaan dengan kode VBA


Jalankan atau jalankan makro yang sama di beberapa lembar kerja secara bersamaan dengan kode VBA

Untuk menjalankan makro di beberapa lembar secara bersamaan tanpa memicunya satu per satu lembar, Anda dapat menerapkan kode VBA berikut, lakukan seperti ini:

1. Tahan ALT + F11 kunci untuk membuka Microsoft Visual Basic untuk Aplikasi jendela.

2. Klik Menyisipkan > Modul, dan tempelkan makro berikut di file Modul Jendela.

Kode VBA: Jalankan makro yang sama di beberapa lembar kerja secara bersamaan:

Sub Dosomething()
    Dim xSh As Worksheet
    Application.ScreenUpdating = False
    For Each xSh In Worksheets
        xSh.Select
        Call RunCode
    Next
    Application.ScreenUpdating = True
End Sub
Sub RunCode()
    'your code here
End Sub

Note: Pada kode di atas, silahkan copy dan paste kode Anda sendiri tanpa Sub menuju dan End Sub footer antara Sub Runcode () dan End Sub skrip. Lihat tangkapan layar:

doc menjalankan makro di semua lembar 1

3. Kemudian letakkan kursor di makro bagian pertama, dan tekan F5 kunci untuk menjalankan kode, dan kode makro Anda akan diterapkan ke satu per satu lembar.


Hapus semua makro dari beberapa buku kerja:

Kutools untuk Excel's Hapus Batch Semua Makro utilitas dapat membantu Anda untuk menghapus semua makro dari beberapa buku kerja yang Anda butuhkan. Unduh dan uji coba gratis Kutools for Excel sekarang!

doc menjalankan makro jika sel berubah 3

Kutools untuk Excel: dengan lebih dari 300 add-in Excel yang praktis, gratis untuk dicoba tanpa batasan dalam 30 hari. Unduh dan uji coba gratis Sekarang!

Alat Produktivitas Kantor Terbaik

馃 Kutools AI Ajudan: Merevolusi analisis data berdasarkan: Eksekusi Cerdas   |  Hasilkan Kode  |  Buat Rumus Khusus  |  Analisis Data dan Hasilkan Grafik  |  Aktifkan Fungsi Kutools...
Fitur Populer: Temukan, Sorot, atau Identifikasi Duplikat   |  Hapus Baris Kosong   |  Gabungkan Kolom atau Sel tanpa Kehilangan Data   |   Putaran tanpa Formula ...
Pencarian Super: VLookup Beberapa Kriteria    VLookup Nilai Berganda  |   VLookup di Beberapa Lembar   |   Pencarian Fuzzy ....
Daftar Drop-down Lanjutan: Buat Daftar Drop Down dengan Cepat   |  Daftar Drop Down yang Bergantung   |  Multi-pilih Drop Down List ....
Manajer Kolom: Tambahkan Jumlah Kolom Tertentu  |  Pindahkan Kolom  |  Alihkan Status Visibilitas Kolom Tersembunyi  |  Bandingkan Rentang & Kolom ...
Fitur Unggulan: Fokus Kisi   |  Tampilan Desain   |   Bar Formula Besar    Manajer Buku Kerja & Lembar   |  Perpustakaan Sumberdaya (Teks otomatis)   |  Pemetik tanggal   |  Gabungkan Lembar Kerja   |  Enkripsi/Dekripsi Sel    Kirim Email berdasarkan Daftar   |  Filter Super   |   Filter Khusus (filter tebal/miring/coret...) ...
15 Perangkat Teratas12 Teks Tools (Tambahkan Teks, Hapus Karakter, ...)   |   50 + Grafik jenis (Gantt Chart, ...)   |   40+ Praktis Rumus (Hitung usia berdasarkan ulang tahun, ...)   |   19 Insersi Tools (Masukkan Kode QR, Sisipkan Gambar dari Jalur, ...)   |   12 Konversi Tools (Angka ke Kata, Konversi Mata Uang, ...)   |   7 Gabungkan & Pisahkan Tools (Lanjutan Gabungkan Baris, Pisahkan Sel, ...)   |   ... dan banyak lagi

Tingkatkan Keterampilan Excel Anda dengan Kutools for Excel, dan Rasakan Efisiensi yang Belum Pernah Ada Sebelumnya. Kutools for Excel Menawarkan Lebih dari 300 Fitur Lanjutan untuk Meningkatkan Produktivitas dan Menghemat Waktu.  Klik Di Sini untuk Mendapatkan Fitur yang Paling Anda Butuhkan...

Deskripsi Produk


Tab Office Membawa antarmuka Tab ke Office, dan Membuat Pekerjaan Anda Jauh Lebih Mudah

  • Aktifkan pengeditan dan pembacaan tab di Word, Excel, PowerPoint, Publisher, Access, Visio, dan Project.
  • Buka dan buat banyak dokumen di tab baru di jendela yang sama, bukan di jendela baru.
  • Meningkatkan produktivitas Anda sebesar 50%, dan mengurangi ratusan klik mouse untuk Anda setiap hari!
Comments (16)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
The original macro "How to run the same macro on multiple worksheets at same time in Excel" is fantastic for my purposes, thanks so much. I was wondering if there's a way to get it to return to the first worksheet where I have a control to run the macro. Currently it goes through 25 worksheets doing my code (autofit & Sort by date) and stops once it's done the last worksheet of the 25. Returning to the first sheet would be the icing on the cake! Thanks in advance for thinking about this.
This comment was minimized by the moderator on the site
is there a way to only do it on selected worksheets and not all?
This comment was minimized by the moderator on the site
Hello, karen,
To run the code on selected sheet, please apply the below code:
Step1: Copy anf paste the below code into the Module Window
'Replace this code with your own, but keep the script inside the parentheses
Sub LCase(ws As Worksheet)
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
For Each Rng In WorkRng
    Rng.Value = VBA.LCase(Rng.Value)
Next
End Sub

Sub RunOnSelectedSheets()
    Dim ws As Worksheet
    For Each ws In ActiveWindow.SelectedSheets
        LCase ws    'change the LCase code name to your own code name
    Next ws
End Sub



Step2: Replace the first section of code above with your own code, but keep the script inside the parentheses. And change the LCase code name to your own code name.

Step3: Then, select the worksheet you want to run this code.
After running the code, your code will be executed on each of the selected sheets.

Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
Terimakasih sebelumnya atas ilmu ilmu yg sudah di share. Saya sudah memakai beberapa VBA anda.

Tapi bolehkan saya meminta tolong untul mencarikan VBA yg tepat untuk mengaktifkan VBA yg sudah ada di sheet tertentu tanpa harus masuk ke sheet tersebut.

Contohnya.
Saya sudah menggunakan vBA anda yg berfungsi untuk mengurutkan data secara otomatis.

Tetapi ketika data yg saya terapkan itu berubah karena hasil pencarian data dari sheet yg berbeda. vBA tersebut tidak aktif. Harus terlebih dahulu masuk ke Sheet Tersebut untuk merubah data dengan manual barulah VBa pengurutan dat tersebut aktif.

Bisakah dicarikan VBA nya?
This comment was minimized by the moderator on the site
It works, but the current sheet is always running twice. The rest sheets are perfect and run only once!
This comment was minimized by the moderator on the site
Hello, hou,
May be you can use the below code to your need:
Sub WorksheetLoop()
         Dim Current As Worksheet
         For Each Current In Worksheets

          'Insert your code here.
           
      End Sub


Note: In the above code, please copy and paste your own code without the Sub heading and End Sub footer.

Please try, hope it can help you!
This comment was minimized by the moderator on the site
Thank you so much! But it's not working. It only runs the current sheet for several times.
This comment was minimized by the moderator on the site
How do you exclude certain sheets and add On Error Resume Next? Thanks in advance
This comment was minimized by the moderator on the site
Before xSh.selectyou have to activate
So,xSh.activatexSh.select
This comment was minimized by the moderator on the site
The code "Run the same macro on multiple worksheets at same time" works perfectly, Thanks !

However I have this error at "xSh.Select" and I don't know why...there is no issue visible in the sheets... AND I don't have any hidden sheets.

The error is '1004': Method'Select' of object '_Worksheet' failed


Thanks in advance for your help
This comment was minimized by the moderator on the site
For those wiFor those with 1004 runtime error, verify you don麓t have any hidden sheets. If you do, unhide them. Then this code snippet works. Greetings.th 1004 runtime error, verify you don麓t have any hidden sheets. If you do, unhide them. Then this code snippet works. Greetings.
This comment was minimized by the moderator on the site
Is there a way to make this run only on unhidden sheets? I need this code to run only on visible sheets.
This comment was minimized by the moderator on the site
or
On Error Resume Next

'above

xSh.Select

This comment was minimized by the moderator on the site
1004 runtime error
This comment was minimized by the moderator on the site
Sub Dosomething()
Dim xSh As Worksheet
Application.ScreenUpdating = False
For Each xSh In Worksheets
xSh.Select
Call RunCode
Next
Application.ScreenUpdating = True
End Sub
Sub RunCode()
With Worksheets("2018")
.EnableOutlining = True
.EnableSelection = xlNoRestrictions
.Protect Password:="workana1234", _
Contents:=True, UserInterfaceOnly:=True
End With
End Sub


Hola! he seguido las pautras pero me se帽ala como error la fila xSh.Select.

Al dar F5 me indica que se ha producido un error 1004 en tiempo de ejecucion.

Error en el metodo "Select" de Objeto "_Worksheet"



Help!!!!
This comment was minimized by the moderator on the site
On Error Resume Next
above
xSh.Select
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
Rate this post:
0   Characters
Suggested Locations