Seite 1 von 1
Was übersehe ich?
Verfasst: Fr, 17.02.2012 19:31
von wellmo
Bei folgendem Code bekomme ich folgende Meldung:
BASIC-Syntaxfehler.
Unerwartetes Symbol: End Sub.
Code: Alles auswählen
Sub Zahlungskonditionen
with thiscomponent.sheets(1)
sheet = ThisComponent.CurrentController.ActiveSheet
for i = 72 to 120
if .getcellbyposition(1 ,i).string = "Zahlungskonditionen" then exit for
if .getcellbyposition(1 ,i).string = "" then
i=i+1
end if
if .getcellbyposition(1 ,i).string = "" then
.getcellbyposition(1 ,i).string = "Zahlungskonditionen"
exit for
end if
next
textcur=sheet.getcellbyposition(1,i).gettext().createtextcursor()
textcur.gotostart(true)
textcur.CharWeight=com.sun.star.awt.FontWeight.BOLD
if .getcellbyposition(1 ,i).string = "Zahlungskonditionen" then
if .sheets(2).getcellbyposition(7 ,10).value > "0" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D11"
i=i+1
if .sheets(2).getcellbyposition(7 ,11).value > "0" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D12"
i=i+1
if .sheets(2).getcellbyposition(7 ,12).value > "0" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D13"
i=i+1
if .sheets(2).getcellbyposition(7 ,13).value > "0" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D14"
i=i+1
if .sheets(2).getcellbyposition(7 ,14).value > "0" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D15"
i=i+1
if .sheets(2).getcellbyposition(7 ,15).value > "0" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D16"
i=i+1
if .sheets(2).getcellbyposition(7 ,16).value > "0" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D17"
i=i+1
if .sheets(2).getcellbyposition(7 ,17).value > "0" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D18"
i=i+1
if .sheets(2).getcellbyposition(7 ,18).value > "0" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D19"
i=i+1
if .sheets(2).getcellbyposition(7 ,19).value > "0" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D20"
end if
end with
End Sub
Ist folgender Code überhaupt korrekt?
Code: Alles auswählen
if .sheets(2).getcellbyposition(7 ,10).value > "0" then
Danke schonmal für die Hilfe.
Gruss
Re: Was übersehe ich?
Verfasst: Fr, 17.02.2012 19:59
von F3K Total
Hi,
gehört nicht zu jedem if ein end if?
Gruß R
Re: Was übersehe ich?
Verfasst: Fr, 17.02.2012 20:21
von wellmo
Folgender Code funktioniert und da ist auch 2 mal "if" und nur einmal "end if" drin.
Code: Alles auswählen
Sub Zahlungskonditionen
with thiscomponent.sheets(1)
sheet = ThisComponent.CurrentController.ActiveSheet
for i = 72 to 120
if .getcellbyposition(1 ,i).string = "Zahlungskonditionen" then exit for
if .getcellbyposition(1 ,i).string = "" then
i=i+1
end if
if .getcellbyposition(1 ,i).string = "" then
.getcellbyposition(1 ,i).string = "Zahlungskonditionen"
exit for
end if
next
textcur=sheet.getcellbyposition(1,i).gettext().createtextcursor()
textcur.gotostart(true)
textcur.CharWeight=com.sun.star.awt.FontWeight.BOLD
end with
End Sub
Re: Was übersehe ich?
Verfasst: Fr, 17.02.2012 20:35
von F3K Total
Jo,
auf das endif kannst Du verzichten, wenn nur
ein Befehl nach dem
then kommt, sonst nicht.
Also etwa so:
Gruß R
Re: Was übersehe ich?
Verfasst: Fr, 17.02.2012 20:39
von wellmo
Aha, wieder was gelernt, danke dir vielmals.
Re: Was übersehe ich?
Verfasst: Fr, 17.02.2012 20:44
von wellmo
Code erweitert und hinter jedes "if" auf ein "end if" gesetzt.
Aber es kommt die gleiche Fehlermeldung
Code: Alles auswählen
Sub Zahlungskonditionen
with thiscomponent.sheets(1)
sheet = ThisComponent.CurrentController.ActiveSheet
for i = 72 to 120
if .getcellbyposition(1 ,i).string = "Zahlungskonditionen" then exit for
if .getcellbyposition(1 ,i).string = "" then
i=i+1
end if
if .getcellbyposition(1 ,i).string = "" then
.getcellbyposition(1 ,i).string = "Zahlungskonditionen"
exit for
end if
next
textcur=sheet.getcellbyposition(1,i).gettext().createtextcursor()
textcur.gotostart(true)
textcur.CharWeight=com.sun.star.awt.FontWeight.BOLD
if .getcellbyposition(1 ,i).string = "Zahlungskonditionen" then
if .sheets(2).getcellbyposition(7 ,10).value > "0" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D11"
i=i+1
end if
if .sheets(2).getcellbyposition(7 ,11).value > "0" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D12"
i=i+1
end if
if .sheets(2).getcellbyposition(7 ,12).value > "0" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D13"
i=i+1
end if
if .sheets(2).getcellbyposition(7 ,13).value > "0" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D14"
i=i+1
end if
if .sheets(2).getcellbyposition(7 ,14).value > "0" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D15"
i=i+1
end if
if .sheets(2).getcellbyposition(7 ,15).value > "0" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D16"
i=i+1
end if
if .sheets(2).getcellbyposition(7 ,16).value > "0" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D17"
i=i+1
end if
if .sheets(2).getcellbyposition(7 ,17).value > "0" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D18"
i=i+1
end if
if .sheets(2).getcellbyposition(7 ,18).value > "0" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D19"
i=i+1
end if
if .sheets(2).getcellbyposition(7 ,19).value > "0" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D20"
end if
end with
End Sub
Re: Was übersehe ich?
Verfasst: Fr, 17.02.2012 20:56
von F3K Total
und dieses:
wellmo hat geschrieben:if .getcellbyposition(1 ,i).string = "Zahlungskonditionen" then
?
es hilft mit Einrückungen zu arbeiten:
Code: Alles auswählen
if i>1 then
msgbox ">1"
if i=2 then msgbox "=2"
else
msgbox "<=1"
endif
Gruß R
Re: Was übersehe ich?
Verfasst: Fr, 17.02.2012 21:06
von wellmo
Ok, nun klappt das, danke, hab mich verwirren lassen von
Code: Alles auswählen
if .getcellbyposition(1 ,i).string = "Zahlungskonditionen" then exit for
if .getcellbyposition(1 ,i).string = "" then
i=i+1
end if
Nun kann ich mal nach dem richtigen Code für folgendes suchen da nicht immer eine Fehlermeldung kommt.
Code: Alles auswählen
if .sheets(2).getcellbyposition(7 ,10).value > "0" then
Danke dir R
Re: Was übersehe ich?
Verfasst: Fr, 17.02.2012 21:26
von Karolus
Hallo
wellmo hat geschrieben:Folgender Code funktioniert und da ist auch 2 mal "if" und nur einmal "end if" drin.
Code: Alles auswählen
Sub Zahlungskonditionen
with thiscomponent.sheets(1)
sheet = ThisComponent.CurrentController.ActiveSheet
for i = 72 to 120
if .getcellbyposition(1 ,i).string = "Zahlungskonditionen" then exit for
if .getcellbyposition(1 ,i).string = "" then
i=i+1
end if
if .getcellbyposition(1 ,i).string = "" then
.getcellbyposition(1 ,i).string = "Zahlungskonditionen"
exit for
end if
next
textcur=sheet.getcellbyposition(1,i).gettext().createtextcursor()
textcur.gotostart(true)
textcur.CharWeight=com.sun.star.awt.FontWeight.BOLD
end with
End Sub
Das ist ja haarsträubend
Code: Alles auswählen
Sub Zahlungskonditionen
bold = com.sun.star.awt.FontWeight.BOLD
with thiscomponent.sheets(1)
for i = 72 to 120
if .getcellbyposition(1 ,i).string = "" then
.getcellbyposition(1 ,i + 1).string = "Zahlungskonditionen"
.getcellbyposition(1,i+1).CharWeight= bold
exit sub
end if
next
end with
End Sub
Karo
Re: Was übersehe ich?
Verfasst: Fr, 17.02.2012 21:38
von wellmo
Hi Karo
Ich bin für jeden Tipp und Verbesserungen dankbar.
Auch wenn es für dich "haarsträubend" ausschaut, für mich ist das so im Moment noch übersichtlicher da ich es Schritt für Schritt nachvollziehen kann was passiert.
und das "exit Sub darf glaub nicht sein, da der Code fertig noch weiter geht:
Ich habs nun auch hinbekommen das es so funktioniert wie ich es mir wünsche.
und das Ergebnis sieht so aus:
Code: Alles auswählen
Sub Zahlungskonditionen
with thiscomponent.sheets(1)
sheet = ThisComponent.CurrentController.ActiveSheet
for i = 72 to 120
if .getcellbyposition(1 ,i).string = "Zahlungskonditionen" then exit for
if .getcellbyposition(1 ,i).string = "" then
i=i+1
end if
if .getcellbyposition(1 ,i).string = "" then
.getcellbyposition(1 ,i).string = "Zahlungskonditionen"
exit for
end if
next
textcur=sheet.getcellbyposition(1,i).gettext().createtextcursor()
textcur.gotostart(true)
textcur.CharWeight=com.sun.star.awt.FontWeight.BOLD
if .getcellbyposition(1 ,i).string = "Zahlungskonditionen" then
if thiscomponent.sheets(2).getcellbyposition(7 ,10).string <> "" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D11"
i=i+1
end if
if thiscomponent.sheets(2).getcellbyposition(7 ,11).string <> "" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D12"
i=i+1
end if
if thiscomponent.sheets(2).getcellbyposition(7 ,12).string <> "" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D13"
i=i+1
end if
if thiscomponent.sheets(2).getcellbyposition(7 ,13).string <> "" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D14"
i=i+1
end if
if thiscomponent.sheets(2).getcellbyposition(7 ,14).string <> "" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D15"
i=i+1
end if
if thiscomponent.sheets(2).getcellbyposition(7 ,15).string <> "" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D16"
i=i+1
end if
if thiscomponent.sheets(2).getcellbyposition(7 ,16).string <> "" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D17"
i=i+1
end if
if thiscomponent.sheets(2).getcellbyposition(7 ,17).string <> "" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D18"
i=i+1
end if
if thiscomponent.sheets(2).getcellbyposition(7 ,18).string <> "" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D19"
i=i+1
end if
if thiscomponent.sheets(2).getcellbyposition(7 ,19).string <> "" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D20"
end if
end if
end with
End Sub
Falls du aber für diesen Code verbesserungen hast, werde ich gerne davon lernen.
Gruss
Re: Was übersehe ich?
Verfasst: Fr, 17.02.2012 21:53
von F3K Total
Nun, vielleicht könntest du z.B. diesen Teil:
Code: Alles auswählen
if thiscomponent.sheets(2).getcellbyposition(7 ,10).string <> "" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D11"
i=i+1
end if
if thiscomponent.sheets(2).getcellbyposition(7 ,11).string <> "" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D12"
i=i+1
end if
if thiscomponent.sheets(2).getcellbyposition(7 ,12).string <> "" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D13"
i=i+1
end if
if thiscomponent.sheets(2).getcellbyposition(7 ,13).string <> "" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D14"
i=i+1
end if
if thiscomponent.sheets(2).getcellbyposition(7 ,14).string <> "" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D15"
i=i+1
end if
if thiscomponent.sheets(2).getcellbyposition(7 ,15).string <> "" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D16"
i=i+1
end if
if thiscomponent.sheets(2).getcellbyposition(7 ,16).string <> "" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D17"
i=i+1
end if
if thiscomponent.sheets(2).getcellbyposition(7 ,17).string <> "" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D18"
i=i+1
end if
if thiscomponent.sheets(2).getcellbyposition(7 ,18).string <> "" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D19"
i=i+1
end if
if thiscomponent.sheets(2).getcellbyposition(7 ,19).string <> "" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D20"
end if
"etwas" kürzen:
Code: Alles auswählen
for k = 10 to 19
if thiscomponent.sheets(2).getcellbyposition(7 ,k).string <> "" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D"+(k+1)
i=i+1
end if
next k
Gruß R
Re: Was übersehe ich?
Verfasst: Fr, 17.02.2012 22:02
von wellmo
Cool, das geht, darf ich dir auch noch meine anderen 200 Codes für ein Facelifting schicken
Danke dir
Re: Was übersehe ich?
Verfasst: Fr, 17.02.2012 22:32
von Karolus
Hallo
Code: Alles auswählen
Sub Zahlungskonditionen2
sheet = ThisComponent.CurrentController.ActiveSheet
sheet2 = thiscomponent.sheets(2)
bold = com.sun.star.awt.FontWeight.BOLD
cond = false
with thiscomponent.sheets(1)
for i = 72 to 120
if .getcellbyposition(1 ,i).string = "" then
.getcellbyposition(1 ,i+1).string = "Zahlungskonditionen"
.getcellbyposition(1,i+1).CharWeight= bold
cond = True
i = i+1
exit for
end if
next i
if not cond then exit sub
for row = 10 to 19
if sheet2.getcellbyposition(7 , row).string <> "" then
.getcellbyposition(1 ,i+1).formula = "=Listenfelder.D" & row +1
i=i+1
end if
next row
end with
End Sub
Karo
Re: Was übersehe ich?
Verfasst: Fr, 17.02.2012 22:54
von F3K Total
wellmo hat geschrieben:Cool, das geht, darf ich dir auch noch meine anderen 200 Codes für ein Facelifting schicken
Danke dir
Klar!
Wenn Du dir das leisten kannst.

R