AW: Zeile einfügen und dann die Formeln eintragen?
17.09.2008 10:48:00
fcs
Hallo Selma,
hier zwei Varianten.
Für die Formeln wird dabei die sprachunabhängige Englische Variante verwendet.
Gruß
Franz
Sub Insert_Task()
Dim Spalte As Long, Zeile As Long
Const Zeile1Formel = 2 '1. Zeile mit Formeln
Zeile = ActiveCell.Row
Rows(Zeile + 1).Insert Shift:=xlUp
If Zeile = Zeile1Formel Then
'Zeile mit Formeln unterhalb der Einfügezeile nach oben kopieren
Rows(Zeile + 1).Copy Destination:=Cells(Zeile, 1)
'Zellinhalte ohne Formel löschen
For Spalte = 1 To ActiveSheet.Cells.SpecialCells(xlLastCell).Column
If Not Cells(Zeile, Spalte).HasFormula Then
Cells(Zeile, Spalte).ClearContents
End If
Next
ElseIf Zeile > Zeile1Formel Then
'Zeile mit Formeln oberhalb der Einfügezeile nach unten kopieren
Rows(Zeile).Copy Destination:=Cells(Zeile + 1, 1)
'Zellinhalte ohne Formel löschen
For Spalte = 1 To ActiveSheet.Cells.SpecialCells(xlLastCell).Column
If Not Cells(Zeile + 1, Spalte).HasFormula Then
Cells(Zeile + 1, Spalte).ClearContents
End If
Next
End If
Rows(Zeille + 1).Select
End Sub
Sub Insert_Task_Alternative()
Dim Spalte As Long, Zeile As Long, strFormel As String
Const Zeile1Formel = 2 '1. Zeile mit Formeln
Zeile = ActiveCell.Row
Rows(Zeile + 1).Insert Shift:=xlUp
'Formeln einfügen
strFormel = "=R[0]C[-3]*50/25"
Cells(Zeile + 1, 4).FormulaR1C1 = strFormel
strFormel = "=IF(OR(R[0]C[-3]="""",R[0]C[-2]=""""),"""",R[0]C[-3]*3.14+1.2+R1C1)"
Cells(Zeile + 1, 5).FormulaR1C1 = strFormel
strFormel = "=CONCATENATE(R[0]C[-12],"" "",R[0]C[-10])"
Cells(Zeile + 1, 20).FormulaR1C1 = strFormel
Rows(Zeille + 1).Select
End Sub