Page 1 of 1

Anzahl Zeichen in Excel zählen

Posted: 22 Sep 2023, 07:48
by Rumborak
Hallo Zusammen,

ich habe ein Excel in deren Spalte A ein x drinnen steht. Allerdings mit Unterbrechung z.B.:
y
x
x
y
y
x
y

Gibt es eine Möglichkeit die Anzahl der x'e zu zählen, die ohne unterbrechung sind? Also oben begonnen, wäre das dann die Anzahl 2.

Danke und Grüße, Thomas

Re: Anzahl Zeichen in Excel zählen

Posted: 22 Sep 2023, 08:01
by Ahk_fan
in Excel mit ZÄHLENWENN
2023-09-22 14_57_53-Mappe1 - Excel.png
2023-09-22 14_57_53-Mappe1 - Excel.png (12.9 KiB) Viewed 918 times
oder siehe hier:
viewtopic.php?f=76&t=105825&p=470045&hilit=excel+count#p470045

in deinem Fall sieht es so aus:

Code: Select all

xl := ComObjActive("excel.application")
lstrw := xl.Range("A" xl.Rows.Count).End(-4162).Row
anz := 0
loop, %lstrw%
{
	if xl.Range("A" A_Index).Value = "x" 
		anz += 1 
}
msgbox % "anz x: " anz  " letze Zeile" lstrw

Re: Anzahl Zeichen in Excel zählen

Posted: 22 Sep 2023, 11:52
by flyingDman
So wie ich es verstehe, möchten Sie die längste ununterbrochene Reihe von „x“ in Spalte A zählen. Versuchen Sie Folgendes:

Code: Select all

xl := ComObjActive("excel.application")
max := 0, cnt := 0
for c in xl.Intersect(xl.range("A:A"), xl.ActiveSheet.UsedRange)
	cnt := (c.value = "x") ? (++cnt, max := max(max, cnt)) : 0

msgbox % max