![]() |
Tipp 0495
|
Formelbezüge umwandeln
|
 |
|
Autor/Einsender: Datum: |
|
Max Kaffl 27.05.2006 |
|
Entwicklungsumgebung: |
|
Excel 2000 |
|
|
Formeln werden, wenn sie in Excel mit dem Formelassistenten erstellt werden, immer mit relativem Bezug erzeugt. Mit
folgender kleinen Routine lässt sich das schnell ändern. Dabei kann zwischen absolutem und relativem Bezug auch
gesondert für Spalten und Zeilen gewählt werden.
|
|
|
Private Sub prcConvertType(lngType As XlReferenceType)
Dim objCell As Range
On Error GoTo err_exit
For Each objCell In Selection
If objCell.HasFormula Then
If Not objCell.HasArray Then
If Application.ReferenceStyle = xlR1C1 Then
objCell.FormulaR1C1 = Application.ConvertFormula _
(Formula:=objCell.FormulaR1C1, _
FromReferenceStyle:=xlR1C1, _
ToAbsolute:=lngType)
ElseIf Application.ReferenceStyle = xlA1 Then
objCell.Formula = Application.ConvertFormula _
(Formula:=objCell.Formula, _
FromReferenceStyle:=xlA1, _
ToAbsolute:=lngType)
Else
objCell.Select
Err.Raise Number:=vbObjectError + 512, Description:= _
"Unbekannter Bezug in der markierten Formel"
End If
ElseIf objCell.HasArray Then
If Application.ReferenceStyle = xlR1C1 Then
objCell.FormulaArray = Application.ConvertFormula _
(Formula:=objCell.FormulaR1C1, _
FromReferenceStyle:=xlR1C1, _
ToAbsolute:=lngType)
ElseIf Application.ReferenceStyle = xlA1 Then
objCell.FormulaArray = Application.ConvertFormula _
(Formula:=objCell.Formula, _
FromReferenceStyle:=xlA1, _
ToAbsolute:=lngType)
Else
objCell.Select
Err.Raise Number:=vbObjectError + 1024, Description:= _
"Unbekannter Bezug in der markierten Arrayformel"
End If
Else
objCell.Select
Err.Raise Number:=vbObjectError + 1536, Description:= _
"Unbekannter Formeltype in der markierten Zelle"
End If
End If
Next
Exit Sub
err_exit:
MsgBox "Fehler " & CStr(Err.Number) & vbLf & vbLf & _
Err.Description, vbCritical, "Fehlermeldung"
End Sub
|
|
|
|
Die im Download befindliche *.bas-Datei kann in Excel im VB-Editor importiert werden.
|
|
Windows-Version |
95 |
 |
|
98 |
 |
|
ME |
 |
|
NT |
 |
|
2000 |
 |
|
XP |
 |
|
Vista |
 |
|
Win
7 |
 |
|
|
Excel-Version |
95 |
 |
|
97 |
 |
|
2000 |
 |
|
2002
(XP) |
 |
|
2003 |
 |
|
2007 |
 |
|
2010 |
 |
|
|
|
Download (1,8
kB)
|
Downloads bisher: [ 444 ]
|
|
|