# Instr Vs instrRev

#### Kavy

##### Well-known Member
Hello, whats the differance between these two.
I would like to know how many charactors my string is back from the very end of the other string, but it keeps giving me from the front!

Thanks![/img]

### Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hi, Kavy.

Looks to me like both functions return the index of the "search" string from the beginning of the "within" string. The difference is that InstrRev starts looking at the end of the "within" string. So, Instr("This String has back in it near the front and near the back as well","back") gives 17, whilst InstrRev("This String has back in it near the front and near the back as well","back") gives 56.

I suppose you could subtract the result of the InstrRev function from the length of the "within" string and add 1 to get the length from the end of the string.

eta: (I didn't find the VBA Help for InstrRev helpful at all, did you? No example, no "see also" link. It must have been one of the last things added.)

Any help at all?

Hi Kavy

InStr() gives you the position of the FIRST match. InStrRev gives you the position of the LAST match. Both positions from the start position of the string.

InStr("between","e") is equal to 2, the position of the first "e".

InStrRev ("between","e") is equal to 6, the position of the last "e".

If you want to know how many characters the string is back from the very end of the other string, take the difference from the legth of the string being searched.

Ex:

Len("between")-InStr("between","een") +1

is equal to 3, the start of the first substring "een" counting from the end of "between".

Hope this helps
PGC

Thanks guys, and ya i found the vb help confusing, and i don't know why i couldn't figure this one out on my own using trial and error could wrap my head around it. I actually used some guys code i found on the net where he changes the function of instrev but u guys way is much simpler and better!

Only thing is i am using file names with more then one "\" so i have to use instrRev

Replies
1
Views
78
Replies
20
Views
396
Replies
7
Views
112
Replies
1
Views
204
Replies
5
Views
187

1,219,894
Messages
6,150,823
Members
450,986
Latest member
Praged

### 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.

### Which adblocker are you using?

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

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