Count the character number behind a certain character

Rav_Singh

New Member
Joined
Jun 29, 2019
Messages
28
I hope someone can assist with this question.

I require to understand the number of characters behind the final '\' character.

Example:

Monday\Tuesday\Wednesday

Answer in next cell = 14 (14 characters behind the final '\')

Or is a possible solution to count where the final '\' is in a cell?

This seems a workable challenge but alas I have failed to come up with a solution.

As always any help will be greatly appreciated.


Rav
 
Last edited:
try PowerQuery

Code:
[SIZE=1]// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Extract = Table.TransformColumns(Source, {{"Column1", each Text.AfterDelimiter(_, "\", {0, RelativePosition.FromEnd}), type text}}),
    Length = Table.TransformColumns(Extract,{{"Column1", Text.Length, Int64.Type}})
in
    Length[/SIZE]

result: 9

Code:
[SIZE=1]// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Position = Table.AddColumn(Source, "BackslashPosition", each Text.PositionOf([Column1],"\",Occurrence.Last)+1)
in
    Position[/SIZE]

Result:

[Table="width:, class:head"]
[tr=bgcolor:#FFFFFF][td=bgcolor:#70AD47]Column1[/td][td=bgcolor:#70AD47]BackslashPosition[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E2EFDA]Monday\Tuesday\Wednesday[/td][td=bgcolor:#E2EFDA]
15​
[/td][/tr]
[/table]
 
Upvote 0

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
This almost works but continues to count back from the first '\' rather than the last '\' from the string.

Appreciate your help on this.

Not sure what you mean. It returns 14 for the example you give, as requested.

Regards
 
Upvote 0
Yes in A2 the string contained two '\'. Was hoping to count the characters behind the final '\' in the string as some cells contain more/less '\' character.

How bizarre, I have here cell A2 as "Monday\Tuesday\Wednesday" and my formula is returning 14 for me. It basically substitutes the final backslash with a pipe and searches for the position, then subtracts 1 from the answer (the length of the text up to the substituted pipe) there should only return a #VALUE ! if the string doesn't contain any backslash - but then you can nest an iferror with the length of the string, only thing I can think of is if it's somehow a different backslash, can you test the unicode of the slash?

=UNICODE(**insert your backslash here**) --> it should be 92
 
Upvote 0
Below is a sub set of the data;

Example
Commercial\Know-how
Commercial\Know-how\Guidance
Commercial\Know-how\Documents & Guidance\Pilot - January 2019
Commercial Lit\Know-how\Databases

Answer
10 for example 1
19 for example 2
40 for example 3
23 for example 4

Hope this helps.





If the formulae you have been provided with don't work, then please supply a sample of the data where they don't work.
 
Upvote 0
Whilst I misunderstood your OP, the other two formulae work for me.
I have also modified mine to work


Book1
ABCD
8Monday\Tuesday\Wednesday141414
9Monday\Tuesday\Wednesday\Thursday\Friday\Saturday404040
10Commercial\Know-how101010
11Commercial\Know-how\Guidance191919
12Commercial\Know-how\Documents & Guidance\Pilot - January 2019404040
13Commercial Lit\Know-how\Databases232323
Dropdowns
Cell Formulas
RangeFormula
B8=LEN(TRIM(LEFT(SUBSTITUTE(A8,"",REPT(" ",100),LEN(A8)-LEN(SUBSTITUTE(A8,"",""))),100)))
C8=-LOOKUP(1,-FIND("ζ",SUBSTITUTE(A8,"","ζ",{1;2;3;4;5;6;7;8;9})))-1
D8=SEARCH("|",SUBSTITUTE(A8,CHAR(92),"|",LEN(A8)-LEN(SUBSTITUTE(A8,CHAR(92),""))))-1
 
Upvote 0
corrected

[Table="width:, class:head"]
[tr=bgcolor:#FFFFFF][td=bgcolor:#70AD47]Column1[/td][td=bgcolor:#70AD47]BackslashPosition[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E2EFDA]Monday\Tuesday\Wednesday[/td][td=bgcolor:#E2EFDA]
14​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td]Commercial\Know-how [/td][td]
10​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E2EFDA]Commercial\Know-how\Guidance[/td][td=bgcolor:#E2EFDA]
19​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td]Commercial\Know-how\Documents & Guidance\Pilot - January 2019[/td][td]
40​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E2EFDA]Commercial Lit\Know-how\Databases[/td][td=bgcolor:#E2EFDA]
23​
[/td][/tr]
[/table]


Code:
[SIZE=1]// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Position = Table.AddColumn(Source, "BackslashPosition", each Text.PositionOf([Column1],"\",Occurrence.Last))
in
    Position[/SIZE]
 
Upvote 0
Thank you all. Solution found.

Oh and tyija1995 when I did rerun your formula it did work.

Really appreciate all your efforts.

A grateful Rav.
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,300
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top