我有 7 个工作表,其中包含有关我大学的一个房间项目的信息,我需要在每张工作表中搜索特定信息,如果它是一个计算机池与否。我想将所有池复制到一个额外的工作表,然后可以更新该工作表中的信息,它会自动更新原始工作表。
我的主要问题是我真的不知道如何调用这样的更新函数。我在底部附加了将所有房间复制到专用表格的代码。提前致谢
Option Explicit
Sub Start()
Dim Suche As String
Dim Blatt1 As String
Dim Blatt2 As String
Dim Blatt3 As String
Dim Blatt4 As String
Dim Blatt5 As String
Dim Blatt6 As String
Dim Blatt7 As String
Dim Result As String
Blatt1 = "1. Stock MZG"
Blatt2 = "5. Stock MZG"
Blatt3 = "6. Stock MZG"
Blatt4 = "7. Stock MZG"
Blatt5 = "8. Stock MZG"
Blatt6 = "1. Stock OEC"
Blatt7 = "2. Stock OEC"
Suche = "Poolraum"
If Len(Suche) Then
Result = "Es wurde(n) " & AuswahlKopieren(Suche, True, Blatt1) & " Zeile(n) aus '" & Blatt1 & "' kopiert!"
Result = Result & vbCrLf & "Es wurde(n) " & AuswahlKopieren(Suche, True, Blatt2) & " Zeile(n) aus '" & Blatt2 & "' kopiert!"
Result = Result & vbCrLf & "Es wurde(n) " & AuswahlKopieren(Suche, True, Blatt3) & " Zeile(n) aus '" & Blatt3 & "' kopiert!"
Result = Result & vbCrLf & "Es wurde(n) " & AuswahlKopieren(Suche, True, Blatt4) & " Zeile(n) aus '" & Blatt4 & "' kopiert!"
Result = Result & vbCrLf & "Es wurde(n) " & AuswahlKopieren(Suche, True, Blatt5) & " Zeile(n) aus '" & Blatt5 & "' kopiert!"
Result = Result & vbCrLf & "Es wurden(n) " & AuswahlKopieren(Suche, True, Blatt6) & " Zeile(n) aus '" & Blatt6 & "' kopiert!"
Result = Result & vbCrLf & "Es wurde(n) " & AuswahlKopieren(Suche, True, Blatt7) & " Zeile(n) aus '" & Blatt7 & "' kopiert!"
MsgBox (Result)
End If
End Sub
Function AuswahlKopieren(SuchStr As String, Optional Ganz As Boolean = False, Optional Arbeitsblattname As String) As Integer
Dim WSq As Worksheet
Dim WSz As Worksheet
Dim SuchColRng As Range
Dim FRng As Range
Dim CRng As Range
Dim CRangeCustom As Range
Dim FirstAdr As String
Dim CArr As Variant
Set WSq = Worksheets(Arbeitsblattname)
Set SuchColRng = WSq.Range("E:E")
Set CRangeCustom = WSq.Range("A:G")
Set WSz = Worksheets("Poolräume")
With SuchColRng
If Ganz Then
Set FRng = .Find(SuchStr, LookIn:=xlValues, LookAt:=xlWhole)
Else
Set FRng = .Find(SuchStr, LookIn:=xlValues, LookAt:=xlPart)
End If
If Not FRng Is Nothing Then
FirstAdr = FRng.Address
Do
If CRng Is Nothing Then
Set CRng = WSq.Rows(FRng.Row)
Else
Set CRng = Union(WSq.Rows(FRng.Row), CRng)
'MsgBox ("WSq.Rows(FRng.Row): " + WSq.Rows(FRng.Row))
End If
Set FRng = .FindNext(FRng)
Loop While Not FRng Is Nothing And FRng.Address <> FirstAdr
End If
End With
If Not CRng Is Nothing Then
Set CRng = Intersect(CRng, CRangeCustom)
CRng.Copy
WSz.Cells(WSz.Cells(WSz.Rows.Count, SuchColRng.Column).End(xlUp).Row + 1, 1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
AuswahlKopieren = CRng.Cells.Count / CRng.Rows(1).Cells.Count
MsgBox ("CRng.Cells.Count: " & CRng.Cells.Count & " CRng.Rows(1).Cells.Count: " & CRng.Rows(1).Cells.Count)
Else
AuswahlKopieren = 0
End If
End Function
Function WSExists(ByVal WSName As String) As Boolean
Dim WS As Worksheet
For Each WS In Worksheets
If WS.Name = WSName Then
WSExists = True
Exit For
End If
Next
End Function