Sub
extractData()
Dim
wkb
As
Workbook
Dim
i&, j
As
Integer
Dim
strErg
As
String
Dim
strDate
As
String
Dim
vntDat
As
Variant
, vntMA
As
Variant
Dim
c
As
Range
Dim
blnret
As
Boolean
Dim
intspalte
As
Integer
Dim
strPfad
As
String
strPfad = "C:\Users\Home\Desktop\Dienstpläne\"
datum = InputBox(
"Bitte Datum prüfen"
,
"Datumseingabe"
, Format(
Date
,
"ddd dd.mm."
))
strDate = datum
vntDat = Array(
"Dienstplan KW51-52 SchichtI.xlsx"
,
"Dienstplan KW51-52 SchichtII.xlsx"
)
For
i = 0
To
1
If
isopenWKB(vntDat(i))
Then
Set
wkb = Workbooks(vntDat(i))
Else
Set
wkb = Workbooks.Open(strPfad & vntDat(i))
End
If
With
wkb.Worksheets(1).UsedRange
vntMA = .Value
Set
c = .Rows(1).Find(what:=strDate, LookIn:=xlValues, lookat:=xlWhole)
If
Not
c
Is
Nothing
Then
intspalte = IIf(c.Column < 10, 10, 17)
For
j = 1
To
UBound(vntMA, 1)
If
vntMA(j, c.Column) =
"F-2"
Then
strErg = strErg &
","
& j
Next
If
Len(strErg)
Then
strErg = Mid(strErg, 2)
With
ThisWorkbook.Worksheets(1)
.Cells.ClearContents
For
j = 0
To
UBound(Split(strErg,
","
))
.Cells(j + 1, 1) = vntMA(Split(strErg,
","
)(j), 1)
.Cells(j + 1, 2) = vntMA(Split(strErg,
","
)(j), 2)
.Cells(j + 1, 3) =
"F-2"
.Cells(j + 1, 4) = vntMA(Split(strErg,
","
)(j), intspalte)
Next
End
With
blnret =
True
End
If
End
If
End
With
wkb.Close
False
Set
wkb =
Nothing
If
blnret
Then
Exit
Sub
Next
End
Sub
<span style=
"color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 18px; background-color: rgb(239, 239, 239);"
>Dieses Makro sucht in 2 Dateien (Dienstplänen) nach einer Spalte und zwar diese Spalte, die den Wert
"F-2"
enthält und ein bestimmtes Datum als Überschrift hat.
In
beiden Datein gibt es z.B. den 16.01., ich will aber nur die Spalte aus der Datei in der F-2 häufig in derSpalte eingetragen ist. Dies funktioniert auch.</span>
<span style=
"color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 18px; background-color: rgb(239, 239, 239);"
>Wie müsste ich das Makro ergänzen, dass genau aus dieser Spalte mit dem bestimmten Datum und dem häufig auftretendem Wert
"F-2"
, auch die Werte
"W-E"
und
"F-0"
übernommen werden?
Muss zwingend aus dieser Spalte kopiert werden. Werte kommen allerdings auch in der anderen Datein mit der Überschrift (z.B. 16.01.) vor!
Vielen Dank für etwaige Hilfe.
Gruß</span>