Ein-IF-Lösung
17.10.2004 00:45:10
Rolf
Hallo K.Rola,
aufgrund deiner Anregung habe ich,
nach dem alten Grundsatz "keine ifs, keine gotos"
eine Lösung mit nur einem if gefunden.
Die, m.E. sinnvolle, Prämisse ist allerdings,
dass die UsedRange nicht rechts bzw. unten anliegt.
Ich konnte es einfach nicht für mich behalten.
Herzliche Grüße
Rolf
Option Base 1
Sub invselect()
Dim x(4, 4)
Dim BE(4)
Dim a, b, c, d As Integer
Dim i, j As Integer
Dim rc, cc As Long
Dim ur As Range
rc = ActiveSheet.Rows.Count
cc = ActiveSheet.Columns.Count
Set ur = ActiveSheet.UsedRange
a = ur.Row
b = ur.Column
c = ur.Rows.Count + a - 1
d = ur.Columns.Count + b - 1
x(1, 1) = 1
x(1, 2) = 1
x(1, 3) = a - 1
x(1, 4) = cc
x(2, 1) = a
x(2, 2) = 1
x(2, 3) = c
x(2, 4) = b - 1
x(3, 1) = a
x(3, 2) = d + 1
x(3, 3) = c
x(3, 4) = cc
x(4, 1) = c + 1
x(4, 2) = 1
x(4, 3) = rc
x(4, 4) = cc
For i = 1 To 2
If x(i, 3) = 0 Or x(i, 4) = 0 Then
For j = 1 To 4
x(i, j) = x(4, j)
Next
End If
Next
For i = 1 To 4
Set BE(i) = Range(Cells(x(i, 1), x(i, 2)), Cells(x(i, 3), x(i, 4)))
Next
Union(BE(1), BE(2), BE(3), BE(4)).Select
End Sub