sind Matrix- Formeln im Bereich...
20.03.2010 15:43:19
Tino
Hallo,
, müsste es so funktionieren.
Sub Test()
Dim obj1 As Range, rngZiel As Range
Dim meAr()
Dim A&, AA&, LRow, LCol
Dim iCalc As Integer
Dim rngFormel As Range
Dim sngTimer As Single
'Quelle
Set obj1 = ActiveSheet.Range("A10")
'Formeln in einem Array speichern
meAr = obj1.Resize(, obj1.Columns.Count + 1).FormulaLocal
'richtige größe herstellen
Redim Preserve meAr(1 To Ubound(meAr), 1 To Ubound(meAr, 2) - 1)
On Error Resume Next 'Fehler umgehen
'sind Formeln im Bereich
If obj1.Count > 1 Then 'mehr als eine Zelle?
Set rngFormel = obj1.SpecialCells(xlCellTypeFormulas)
Else
If obj1.HasFormula Then Set rngFormel = obj1
End If
'Ziel- Zelle wählen
Set rngZiel = Application.InputBox("Wählen Sie das Ziel", "Zelle auswählen", Type:=8)
On Error GoTo 0
If Not rngZiel Is Nothing Then 'keine Zelle gewählt
With Application
iCalc = .Calculation
.EnableEvents = False
.ScreenUpdating = False
.Calculation = xlCalculationManual
On Error GoTo ErrorH 'Fehler abfangen
obj1.Copy rngZiel(1, 1) 'Bereich kopieren
If Not rngFormel Is Nothing Then 'sind Formeln vorhanden?
'Normale Formeln einfügen
rngZiel.Resize(Ubound(meAr), Ubound(meAr, 2)).FormulaLocal = meAr
'1. Zeile und Spalte aus Quelle
LRow = obj1(1, 1).Row
LCol = obj1(1, 1).Column
'alle Formelzellen durchlaufen wegen Matrix- Formeln
For Each rngFormel In rngFormel
If rngFormel.HasArray Then 'ist dies eine Matrix- Formel?
'Formel als Matrix- Formel einfügen
rngFormel.Offset(rngFormel.Row - LRow, rngFormel.Column - LCol).FormulaArray = _
meAr(rngFormel.Row - LRow + 1, rngFormel.Column - LCol + 1)
End If
Next rngFormel
End If
ErrorH:
If Err.Number <> 0 Then 'Fehler aufgetreten?
'Fehlermeldung ausgeben
MsgBox Err.Description, _
vbCritical + vbMsgBoxSetForeground + vbMsgBoxHelpButton, _
"Error: " & Err.Number, Err.HelpFile, Err.HelpContext
End If
.EnableEvents = True
.ScreenUpdating = True
.Calculation = iCalc
End With 'Application
End If
End Sub
Gruß Tino