I'm trying to write a VBA Macro, but I'm new to this. (And I'm german, sorry for my bad english). I found some useful Code snippets here on StackOverflow, but I can't adapt it for my Needs. I have a workbook with several sheets, and some of them have the same structure. In These sheets in column C, all have a date. The macro should look in These sheets, if the date is like "00.01.1900" and then delete this row. I tried two versions, but None of them worked. It just happend Nothing, so Maybe the walkthrough of the sheets is wrong? Or the string matching does not work?
Version 1:
Dim str As String, w As Long, m As Variant, wss As Variant
wss = Array("Schritt3-WEA1", "Schritt3-WEA2", "Schritt3-WEA3", "Schritt3-WEA4", _
"Schritt3-WEA5", "Schritt3-WEA6", "Schritt3-WEA7", "Schritt3-WEA8", "Schritt3-WEA9" _
, "Schritt3-WEA15", "Schritt3-WEA16", "Schritt3-WEA17", "Schritt3-WEA18", _
"Schritt3-WEA19", "Schritt3-WEA20", "Schritt3-WEA21", "Schritt3-WEA22", _
"Schritt3-WEA23", "Schritt3-WEA28", "Schritt3-WEA29", "Schritt3-WEA36")
str = "00.01.1900"
If CBool(Len(str)) And str <> "False" Then
With ThisWorkbook
For w = LBound(wss) To UBound(wss)
With .Worksheets(wss(w))
m = Application.Match(str, .Columns(3), 0)
Do While Not IsError(m)
.Cells(m, "A").EntireRow.Delete
m = Application.Match(str, .Columns(3), 0)
Loop
End With
Next w
End With
End If
Version 2:
Dim wks As Worksheet
Dim arrSheets As Variant
Dim iShCount As Integer
arrSheets = Array("Schritt3-WEA1", "Schritt3-WEA2", "Schritt3-WEA3", "Schritt3-WEA4", _
"Schritt3-WEA5", "Schritt3-WEA6", "Schritt3-WEA7", "Schritt3-WEA8", "Schritt3-WEA9" _
, "Schritt3-WEA15", "Schritt3-WEA16", "Schritt3-WEA17", "Schritt3-WEA18", _
"Schritt3-WEA19", "Schritt3-WEA20", "Schritt3-WEA21", "Schritt3-WEA22", _
"Schritt3-WEA23", "Schritt3-WEA28", "Schritt3-WEA29", "Schritt3-WEA36")
For Each wks In Worksheets
For iShCount = 0 To UBound(arrSheets)
If wks.Name = arrSheets(iShCount) Then
'** Ermittlung der letzten Zeile in Spalte C
lz = Cells(Rows.Count, 3).End(xlUp).Rows.Row
'** Durchlauf aller Zeilen
For t = lz To 15 Step -1
'Z?hlung r?ckw?rts bis Zeile 15
'Abfragen, ob in der dritten Spalte "00.01.1900" steht
If Cells(t, 3).Value = "00.01.1900" Then
Rows(t).Delete Shift:=xlUp
End If
Next t
End If
Next
Next
Thanks a lot in Advance!