Problem setting variable based on partial cell string

DaveBlakeMAAT

Board Regular
Joined
Feb 28, 2016
Messages
190
Hi all

Sorry I am probably being thick, but I am having a problem setting a variable based on a partial string within a cell.

Code:
AccountingYear = Trim(Mid("A5", Find("201", "A5", 1), 4))

It is giving me a syntax error which I suspect is due to the find statement.

My scenario is I have the following text string

"ACCOUNTING PERIOD 1 2016/2017 01-APR-2016 TO 30-APR-2016" in a cell

and I need to be able to extract the accounting period for 1 variable (which I have working using Trim(Mid(Range("A5"), 18, 2)), however I am struggling to extract the year for the 2nd variable.

Any ideas

Regards

Dave
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Use:
Code:
AccountingYear = Trim(Mid(Range("A5"), InStr(Range("A5"), "201"), 4))
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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