1
votes

How to count occurrences of a specific character in a Google Sheets cell appearing last in the cell (and ignoring the other occurrences of the same character appearing before last in the cell)?

I'm trying the following:

If cell C1 contains a period (".") as the last character in the cell C1, then return 1 as a result, else (if cell C1 contains no period, or periods before the last character without any period as the last character in Cell C1) return 0 or blank or ignore.

I've tried this formula so far, but it returns 1 even when there's a period before the last character too :

=COUNTIF(C1,"*.*")

Following this tutorial:

Here's a screenshot of the result I get:

https://imgur.com/S7MhICk

I've also tried to add space at the end of the criterion, but it then ignores it:

=COUNTIF(C1,"*.*")

Here's a screenshot of the 2nd result I get:

https://imgur.com/WUv8i9c

What I would like as a result would be:

  1. Help. Help. (1) (counts the occurrence of the last "." only)
  2. Help. Help (0) (ignore count)
  3. Help. (1)

Where the counting criterion would be specific to the last character, and the last character being a period (".")

EDIT:

I also had a look at this about the =RIGHT function and it got me thinking:

How do I get the last character of a string using an Excel function?

I came up with this and it seems to work as well:

=IF(RIGHT(C1, 1)=".","1","") 

to return a string ("1")

or

=IF(RIGHT(C1, 1)=".", 1, 0) 

(for numerical value return of 1 and 0)

0

Finally I added how to select these characters as well as last characters too, with the help of the OR operator that way:

("!") ("?") ("...") ("—")

=IF(OR(RIGHT(C1, 1)=".",RIGHT(C1, 1)="!",RIGHT(C1, 1)="?",RIGHT(C1, 1)="...",RIGHT(C1, 1)="—"),1,"")

https://imgur.com/5QSvB8d

1

1 Answers

1
votes

try like this:

=ARRAYFORMULA(IFERROR(IF(REGEXEXTRACT(A20:A, ".$")=".", 1, 0)))

0


=ARRAYFORMULA(IF(LEN(A1:A), 
 IF(IFERROR(REGEXEXTRACT(A1:A, "\...$|\?$|!$|—$|\.$"))<>"", 1, 0), ))

0