Excel und Apple Script - repeat mit Erhöhung eines Wertes

mitypsilon

Neues Mitglied
Thread Starter
Dabei seit
04.11.2010
Beiträge
8
Reaktionspunkte
0
hallo zusammen,

folgendes Problem:

ich habe eine Tabelle, in der in Spalte 1 Werte von 0-5 stehen und in Spalte 2 Bezeichnungen.
Ich habe versucht, ein Apple Script zu schreiben, das jede Zeile löscht, in der in Spalte 1 eine "0" steht.

tell application "Microsoft Excel"
tell document 1
tell sheet 1
repeat until (value of range "A1" > 0)
if value of range "A1" = 0 then
delete row 1
end if
end repeat
end tell
end tell
end tell


Dieses Script löscht, wenn in A1 eine 0 steht, die Zeile 1, wenn dann wieder in A1 eine 0 steht, erneut usw., bis in A1 keine 0 mehr steht.
Jetzt soll automatisch mit Zeile 2 fortgefahren werden, dann mit allen anderen Zeilen.

Ich könnte den "tell sheet 1"-Bereich einfach duplizieren und auf Zeile 2 anpassen, und das dann 500mal wiederholen, aber das geht doch bestimmt auch ganz einfach automatisch, oder?

1000 Dank!
 
Cool, wusste gar nicht dass Applescript Excel kann :thumbsup:

Vorweg:
Ich bin absolut kein AS-Profi!
Gut möglich, dass das auch viel besser geht.

Habe aber auf die Schnelle was gebastelt das zu klappen scheint :)

Code:
set x to 1
set Zelle to "A" & x

tell application "Microsoft Excel"
	tell document 1
		tell Sheet 1
			repeat until (Value of Cell Zelle = 9)
				set Zelle to "A" & x
				repeat until (Value of Cell Zelle > 0)
					if (Value of Cell Zelle = 0) then
						Delete Row x
					end if
				end repeat
				set x to x + 1
			end repeat
		end tell
	end tell
end tell

Anmerkung:
Ich habs nicht geschafft die erste Repeat-Schleife bei der ersten leeren Zelle zu beenden. Hab dann dafür die Zahl 9 genommen (repeat until (Value of Cell Zelle = 9)). D.h. es muss ganz am Ende der Liste, also in die Zelle nach dem letzten Eintrag in Spalte 1 eine 9 eintragen werden um dort das Script zu beenden.
Alternativ müsste man das Script manuell beenden wenn die Liste durch ist.
 
super! Vielen Dank, das war ja mal ne schnelle Antwort und funktionieren tut's auch!
 
hm. Kann man das Script vielleicht so ändern, dass die repeat-Schleife beendet wird, wenn eine komplett leere Zeile erreicht wird?
 
So. Das Script wird nun beendet, sobald in Spalte B nix mehr steht.

Code:
set x to 1
set y to 1
set ZelleA to "A" & x
set ZelleB to "B" & x

tell application "Microsoft Excel"
	tell Sheet 1 of document 1
		repeat while (y = 1)
			repeat until (Value of Cell ZelleA > 0)
				if (Value of Cell ZelleB = 0) then
					set y to 0
					exit repeat
				end if
				if (Value of Cell ZelleA = 0) then
					Delete Row x
				end if
			end repeat
			set x to x + 1
			set ZelleA to "A" & x
			set ZelleB to "B" & x
		end repeat
	end tell
end tell
 
Zurück
Oben Unten