Gruppe
Druck
Problem
Das Start- und Enddatum eines zum Drucken auszuwählenden Bereiches sollen über InputBox abgefragt werden.
StandardModule: Modul1
Sub DatePrint()
Dim varStart As Variant, varEnd As Variant
Dim dStart As Double, dEnd As Double
Dim sStart As String, sEnd As String
sStart = InputBox("Start:", , "12.02.01")
If sStart = "" Then Exit Sub
sEnd = InputBox("Ende:", , "15.03.01")
If sEnd = "" Then Exit Sub
On Error Resume Next
dStart = CDbl(DateValue(sStart))
dEnd = CDbl(DateValue(sEnd))
If Err > 0 Then
Err.Clear
MsgBox "Ungültige Eingaben!"
Exit Sub
End If
If dEnd < dStart Then
Beep
MsgBox "Das Enddatum darf nicht kleiner " & _
"als das Startdatum sein!"
End If
varStart = Application.Match(dStart, Columns(1), 0)
varEnd = Application.Match(dEnd, Columns(1), 0)
ActiveSheet.PageSetup.PrintArea = _
Range(Cells(varStart, 1), Cells(varEnd, 1)).Address
ActiveSheet.PrintPreview
End Sub