AW: Fenster dynamisch fixieren
06.10.2009 18:01:25
Tino
Hallo,
versuche es mal so, es werden beim öffnen nur die letzten 4 benutzten Spalten
(von der letzten aus gezählt) eingeblendet.
kommt als Code in DieseArbeitsmappe
Option Explicit
Private Sub Workbook_Open()
Dim rLetzte As Range
Application.ScreenUpdating = False
With ThisWorkbook.Sheets(Tabelle1.Name)
Set rLetzte = FindLetzte(Sheets(.Name))
If rLetzte.Column > 4 Then
.Columns.EntireColumn.Hidden = True
.Range(.Columns(rLetzte.Column - 3), .Columns(rLetzte.Column)).EntireColumn.Hidden = False
Application.Goto .Cells(1, rLetzte.Column - 3), True
End If
End With
Application.ScreenUpdating = True
End Sub
kommt als Code in Modul1
Option Explicit
Function FindLetzte(mySH As Worksheet) As Range
Dim LRow As Long, LCol As Long
Dim A As Long
With mySH.UsedRange
On Error Resume Next
'Finde Zeile
LRow = .Find("*", , xlValues, xlWhole, xlByRows, xlPrevious, False, False).Row
LRow = Application.Max(LRow, .Find("*", , xlFormulas, xlWhole, xlByRows, xlPrevious).Row)
If LRow = 0 Then LRow = 1
'Finde Spalte
For A = .Columns(.Columns.Count).Column To .Columns(1).Column Step -1
LCol = mySH.Columns(A).Find("*", , xlValues, xlWhole, xlByRows, xlPrevious).Row
LCol = Application.Max(LCol, mySH.Columns(A).Find("*", , xlFormulas, xlWhole, xlByRows, xlPrevious).Row)
If LCol > 1 Then: LCol = A: Exit For
Next A
If LCol = 0 Then LCol = 1
End With
Set FindLetzte = mySH.Cells(LRow, LCol)
End Function
Gruß Tino