Gruppe
Dialog
Problem
Eine in eine UserForm-TextBox einzugebende Zahl soll in Spalte 1 gesucht und die Fundzeile bis Spalte R in eine neue Arbeitsmappe kopiert werden. Die Tabellen 1 bis 5 sind zu durchsuchen.
ClassModule: frmSearch
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdSearch_Click()
If txtSearch.Text = "" Then Exit Sub
Call MultiSuche(CLng(txtSearch.Text))
Unload Me
End Sub
StandardModule: basMain
Sub CallForm()
frmSearch.Show
End Sub
Sub MultiSuche(strSearch As Long)
Dim wks As Worksheet
Dim rng As Range
Dim iRow As Integer
Dim sFind As String
Workbooks.Add
For Each wks In ThisWorkbook.Worksheets
Set rng = wks.Cells.Find(strSearch)
If Not rng Is Nothing Then
sFind = rng.Address
Do
iRow = iRow + 1
wks.Range(wks.Cells(rng.Row, 1), _
wks.Cells(rng.Row, 18)).Copy _
Cells(iRow, 1)
Set rng = wks.Cells.FindNext(After:=rng)
If rng.Address = sFind Then Exit Do
Loop
End If
Next wks
End Sub