Sub letzte()
MsgBox Cells(5, Columns.Count).End(xlToLeft).Column 'letzte Spalte
End Sub
Gruß MatthiasSub MatrixAusfuellen()
Dim wksMatrix As Worksheet, wksQuelle As Worksheet
Dim Zeile As Long, Spalte As Long, StatusCalc As Long
On Error GoTo Fehler
Dim DatAnfang As Date
DatAnfang = Now
Set wksMatrix = Workbooks("Matrix.xls").Worksheets("Matrix")
Set wksQuelle = Workbooks("Berechnung.xls").Worksheets("Calculation")
With Application
StatusCalc = .Calculation
.Calculation = xlCalculationManual
.EnableEvents = False
.ScreenUpdating = False
End With
With wksMatrix
For Zeile = 6 To .Cells(.Rows.Count, 1).End(xlUp).Row 'letzte Zeile
For Spalte = 3 To .Cells(5, Columns.Count).End(xlToLeft).Column 'letzte Spalte
Application.StatusBar = "Zeile " & Zeile & " / Spalte " & Spalte & " wird bearbeitet."
wksQuelle.Range("M1").Value = .Cells(Zeile, 1).Value
wksQuelle.Range("M5").Value = .Cells(1, Spalte).Value
wksQuelle.Calculate ' neu
.Cells(Zeile, Spalte).Value = _
Application.WorksheetFunction.Round(wksQuelle.Range("M10").Value, 3) 'neu
Next
Next
End With
Fehler:
With Application
.StatusBar = False
StatusCalc = .Calculation
.Calculation = StatusCalc
.EnableEvents = True
.ScreenUpdating = True
End With
With Err
Select Case .Number
Case 0 'kein fehler
Case Else
MsgBox Format(Now - DatAnfang, "hh:mm:ss"), , "Makro-Laufzeit + Fehler-Nr. " & .Number & vbLf _
& .Description
End Select
End With
MsgBox Format(Now - DatAnfang, "hh:mm:ss"), , "Makro-Laufzeit - FERTIG!" 'alt: "Fertig!"
End Sub
Es wird eine Matrix "abgearbeitet" - Alle Werte der Spalte A (ab A6 nach unten) undFunction 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).Column
LCol = Application.Max(LCol, mySH.Columns(A).Find("*", , xlFormulas, xlWhole, xlByRows, xlPrevious).Column)
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
Sub Beispiel()
MsgBox FindLetzte(ActiveSheet).Address
End Sub
Gruß Tino