in folgendem Beispiel möchte ich per VBA den Druckbereich festlegen - von dem Datum in Zelle A3 bis zu dem Datum in A4 + Spalte rechts neben Spalte A.
https://www.herber.de/bbs/user/66593.xls
Danke für eine Lösung.
Gruß
Karsten
Sub Druckbereich()
Dim zeile2 As Integer
Dim address1 As String
Dim address2 As String
Dim c As Object
Dim i As Integer
With Sheets("Tabelle1").Range("a7:a1000")
Set c = .Find(Cells(3, 1), LookIn:=xlValues)
If Not c Is Nothing Then
address1 = c.Address
Else
MsgBox ("Datum aus Zelle " & Cells(3, 1).Address & " ist nicht vorhanden")
Exit Sub
End If
Set c = .Find(Cells(4, 1), LookIn:=xlValues)
If Not c Is Nothing Then
zeile2 = c.Row
Else
MsgBox ("Datum aus Zelle " & Cells(4, 1).Address & " ist nicht vorhanden")
Exit Sub
End If
End With
For i = 2 To Sheets("Tabelle1").Columns.Count
If Columns(i).EntireColumn.Hidden = False Then
address2 = Cells(zeile2, i).Address
Exit For
End If
Next i
Worksheets("Tabelle1").PageSetup.PrintArea = address1 & ":" & address2
End Sub
Gruss Ewald