Forum Discussion
Jungdra
Sep 26, 2020Copper Contributor
Count in a row until content changes, then count this next content until it changes and so on
Hello Community, it is easier to see what I am looking for, than to explain. I have a table with 15 columns and a lot of rows. In each column is a letter and in a row, they change a lot. They are no...
- Sep 26, 2020
Create the following custom VBA function:
Function CountLetters(rng As Range) As String Dim i As Long Dim s As String Dim c As String Dim n As Long c = rng(1).Value For i = 1 To rng.Count If rng(i).Value = c Then n = n + 1 Else If i > 1 Then s = s & ", " & n & "x" & c End If c = rng(i).Value n = 1 End If Next i s = s & ", " & n & "x" & c CountLetters = Mid(s, 3) End FunctionLet's say the first row with letters is A2:O2.
Enter the following formula in P2:
=CountLetters(A2:O2)
Fill down to the last row with letters.
HansVogelaar
Sep 26, 2020MVP
Create the following custom VBA function:
Function CountLetters(rng As Range) As String
Dim i As Long
Dim s As String
Dim c As String
Dim n As Long
c = rng(1).Value
For i = 1 To rng.Count
If rng(i).Value = c Then
n = n + 1
Else
If i > 1 Then
s = s & ", " & n & "x" & c
End If
c = rng(i).Value
n = 1
End If
Next i
s = s & ", " & n & "x" & c
CountLetters = Mid(s, 3)
End Function
Let's say the first row with letters is A2:O2.
Enter the following formula in P2:
=CountLetters(A2:O2)
Fill down to the last row with letters.
Jungdra
Oct 01, 2020Copper Contributor
Hallo Hans,
entschuldigung, ich hatte eine Benachrichtigung bei Antwort erwartet, aber es kam keine. Habe Deine Lösung gerade erst entdeckt. Freue mich drauf sie auszuprobieren, aber das muss ein paar Tage warten. Vielen lieben Dank schon mal vorab!
Viele Grüße,
Claudia
entschuldigung, ich hatte eine Benachrichtigung bei Antwort erwartet, aber es kam keine. Habe Deine Lösung gerade erst entdeckt. Freue mich drauf sie auszuprobieren, aber das muss ein paar Tage warten. Vielen lieben Dank schon mal vorab!
Viele Grüße,
Claudia