Wert in Zeile einfrieren
19.09.2014 10:02:38
Bonduca
ich möchte gerne nur die Zeile 14 einfrieren, wenn die Begriffe in Grafikdaten!033 und Tabelle1 Zeile 7 zusammenpassen.
Mein Code vergleicht Zeile 7 und Grafikdaten!O33 korrekt, aber er friert Zeile 14 bis hinauf zu Zeile 7 ein.
Weiß jemand wie man das lösen kann?
Sub Zeile14_einfrieren()
Monat_einfrieren "Tabelle1", "Grafikdaten"
End Sub
Function Monat_einfrieren(Ziel As String, Quelle As String)
Dim lastrow As Long
Dim Spalte As Long, lastColumn As Long
Dim strMonat As String
Dim wsZiel As Worksheet
Set wsZiel = Worksheets(Ziel)
strMonat = Worksheets(Quelle).Range("O33")
With Worksheets(Ziel)
If MsgBox("Daten für Monat """ & strMonat & """ in Tabellenblatt """ & .Name & """ _
einfrieren?", vbQuestion + vbOKCancel, "Monatsdaten einfrieren") = vbCancel Then Exit Function
lastColumn = .Cells(7, .Columns.Count).End(xlToLeft).Column 'Monate in Zeile 7
Application.ScreenUpdating = False
For Spalte = 2 To lastColumn
If Left(.Cells(7, Spalte), Len(strMonat)) = strMonat Then 'Monate in Zeile 7
lastrow = .Cells(.Rows.Count, Spalte).End(xlUp).Row
If lastrow > 4 Then
With .Range(.Cells(14, Spalte), .Cells(14, Spalte).End(xlUp)) 'Zeile
.Value = .Value
End With
End If
End If
Next
Application.ScreenUpdating = True
End With
End Function