Is it possible for Instr to be started at the middle of a text?

Peterso

Board Regular
Joined
Nov 28, 2012
Messages
102
let say I have a text x="I am a happy man"

If I set y=Instr(x, a), y is equal to 3. However I want y to be 9 which is the location of the "a" in "happy". How can I do
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Maybe this....

Code:
Sub MM1()
y = InStr(1, ActiveCell, "ha") + 1
End Sub
 
Upvote 0
let say I have a text x="I am a happy man"

If I set y=Instr(x, a), y is equal to 3. However I want y to be 9 which is the location of the "a" in "happy". How can I do

I don't understand the requirement here.

If you know beforehand where to start, say from the 8th character then it would be like this:

Code:
x = "I am a happy man"
y = InStr(8, x, "a")

but if you want to find the 3rd occurence of "a" then it would be like this:

Code:
x = "I am a happy man"
y = InStr(1, x, "a")
y = InStr(1 + y, x, "a")
y = InStr(1 + y, x, "a")

or do you want to find "a" in "happy"? since we know "a" is the second char of "happy", then:
Code:
y = InStr(1, x, "happy") + 1
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,543
Members
449,089
Latest member
davidcom

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