Bagaimana cara mengulang baris sampai nilai tertentu ditemukan di Excel?
Dalam beberapa kasus, Anda mungkin ingin mengulang baris satu per satu hingga nilai tertentu ditemukan di lembar. Di sini saya memperkenalkan kode makro untuk membantu Anda mengulang data sampai nilai tertentu bertemu.
Ulangi sampai nilai tertentu
1. tekan Alt + F11 kunci untuk mengaktifkan Microsoft Visual Basic untuk Aplikasis jendela.
2. klik Menyisipkan > Modul, tempel kode di bawah ini ke tempat kosong Modul.
VBA: Ulangi baris sampai nilai tertentu
Sub LoopUntilSpecificValue()
'UpdatebyExtendoffice20161222
Dim fStr As String
Dim strActAddress As String
Dim fbool As Boolean
Dim cnt As Long, cntRow As Long
Dim xRg As Range, yRg As Range, zRg As Range
fbool = False
strActAddress = ""
cnt = 0
On Error Resume Next
Set zRg = ActiveSheet.UsedRange
cntRow = zRg.Rows.Count
Set xRg = Application.InputBox _
(Prompt:="Range select..", Title:="Kutools for Excel", Type:=8)
fStr = Application.InputBox _
(Prompt:="Search string?", Title:="Kutools for Excel", Type:=2)
Application.ScreenUpdating = False
For Each yRg In xRg
If yRg.Row > cntRow Then
MsgBox "Value not found ", vbInformation, "Kutools for Excel"
Application.ScreenUpdating = True
Exit Sub
End If
If yRg.Value2 = fStr Then
Application.ScreenUpdating = True
yRg.Activate
fbool = True
strActAddress = yRg.Address
MsgBox "Value found in cell " & strActAddress, vbInformation, "Kutools for Excel"
Exit Sub
Else
cnt = cnt + 1
End If
Next yRg
If cnt = xRg.Count Then
MsgBox "Value not found ", vbInformation, "Kutools for Excel"
End If
Application.ScreenUpdating = True
End Sub
3. tekan F5 key, sebuah dialog muncul untuk memilih kolom yang akan diputar. Lihat tangkapan layar:
4. klik OK, dan ketik string yang ingin Anda temukan di dialog kedua yang muncul. Lihat tangkapan layar:
5. Klik OK. Ini akan mengulang melalui seleksi sampai nilai yang ditentukan ditemukan.
Alat Produktivitas Kantor Terbaik
Tingkatkan Keterampilan Excel Anda dengan Kutools for Excel, dan Rasakan Efisiensi yang Belum Pernah Ada Sebelumnya. Kutools for Excel Menawarkan Lebih dari 300 Fitur Canggih untuk Meningkatkan Produktivitas dan Menghemat Waktu. Klik Di Sini untuk Mendapatkan Fitur yang Paling Anda Butuhkan...
Office Tab Menghadirkan antarmuka Tab ke Office, dan Membuat Pekerjaan Anda 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!
