1.9k Aufrufe
in Tabellenkalkulation von ahorn38 Experte (3.3k Punkte)
Hallo,

ich wollte eine Excelformel in einen Code einbauen mit fomulalocal mache dabei aber etwas falsch. Kann mir jemand sagen, wie ich Syntax für diese Formel aussehen müsste, die im Excel sonst funktioniert:

Excel:
=WENNFEHLER(WENN($L2=1;30;WENN($L2=2;15;WENN($L2=3;10;WENN($L2=4;8;WENN($L2=5;7;"")))));"")


Code: ????
Cells(k, 14).FormulaLocal = "=WENNFEHLER(WENN(cells(k,12)=1;30;WENN(cells(k,12)=2;15;WENN(cells(k,12)=3;10;WENN(cells(k,12)=4;8;WENN(cells(k,12)=5;7;"")))));"")"

Danke und Gruß Andreas

4 Antworten

0 Punkte
von hajo_zi Experte (9.1k Punkte)
Hallo Andreas,

nicht Cells sonder z.b. A3 oder " & cells(k,12).address & "

Gruß Hajo
0 Punkte
von ahorn38 Experte (3.3k Punkte)
Hallo,

habe das jetzt wie oben beschrieben ersetzt:

Cells(k, 14).FormulaLocal = "=WENNFEHLER(WENN(" & Cells(k, 12).Address & "=1;30;WENN(" & Cells(k, 12).Address & "=2;15;WENN(" & Cells(k, 12).Address & "=3;10;WENN(" & Cells(k, 12).Address & "=4;8;WENN(" & Cells(k, 12).Address & "=5;7;"")))));"")"

klappt aber noch nicht...????
Kannst du noch mal helfen? Danke.
0 Punkte
von hajo_zi Experte (9.1k Punkte)

Option Explicit

Sub Formel()
Dim K As Long
K = 12
Cells(K, 14).FormulaLocal = "=WENNFEHLER(WENN(" & Cells(K, 12).Address & "=1;30;WENN(" _
& Cells(K, 12).Address & "=2;15;WENN(" & Cells(K, 12).Address & "=3;10;WENN(" _
& Cells(K, 12).Address & "=4;8;WENN(" & Cells(K, 12).Address & "=5;7;"""")))));"""")"
End Sub


Gruß Hajo
0 Punkte
von ahorn38 Experte (3.3k Punkte)
Vielen Dank Hajo,

ich habe jetzt auch dank deiner Hilfe eine funktionierenden Code mit dem Spaltenbuchstaben hingekriegt:

Cells(k, 14).FormulaLocal = "=Wenn(L" & k & "=1;30;Wenn(L" & k & "=2;15;Wenn(L" & k & "=3;10;Wenn(L" & k & "=4;8;Wenn(L" & k & "=5;7;"""")))))"

Vielen Dank und Gruß
Andreas

Deine Antwort

Dein angezeigter Name (optional):
Datenschutz: Deine Email-Adresse benutzen wir ausschließlich, um dir Benachrichtigungen zu schicken. Es gilt unsere Datenschutzerklärung.
Anti-Spam-Captcha:
Bitte logge dich ein oder melde dich neu an, um das Anti-Spam-Captcha zu vermeiden.
...