Finding the Maximal String, Based on Alphabetic Order

helivw

New Member
Joined
Oct 6, 2018
Messages
26
I have a column with data:
AB001
AB002
EF001
EF002
EF003
KE001
KE002
KE003
AB003
The formule which gives me the Maximum String in the Strings starting with EF (the result of my formula => EF003) is:
Code:
="EF"&TEXT(MAX((--(LEFT(A1:A9,2)="EF")*(RIGHT(A1:A9,3)))),"000") with [COLOR=#333333]Ctl+Shift+Enter NOT just Enter [/COLOR]

Converting to vba gives:
Code:
Range("B1").Value = [="EF"&TEXT(MAX((--(LEFT(A1:A9,2)="EF")*(RIGHT(A1:A9,3)))),"000")]

I try to replace "EF" by a variable: EF_String="EF"
Code:
[COLOR=#333333]Range("B1").Value = [=EF_String&TEXT(MAX((--(LEFT(A1:A9,2)=EF_String)*(RIGHT(A1:A9,3)))),"000")][/COLOR]
I get error 2015 as result

Thanks
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
You cannot use the square bracket notation if you have variables from the VB world that need to be included into the formula; rather, you must use the Evaluate function (which the square brackets are a short-hand for). Untested, but I think this should work for you...
Code:
[table="width: 500"]
[tr]
	[td]Range("B1").Value = Evaluate("""" & EF_String & """&TEXT(MAX((--(LEFT(A1:A9,2)=""" & EF_String & """)*(RIGHT(A1:A9,3)))),""000"")")
[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
How about
Code:
Range("B2").Value = Evaluate("=" & Chr(34) & EF_String & Chr(34) & " &TEXT(MAX((--(LEFT(A1:A9,2)=" & Chr(34) & EF_String & Chr(34) & ")*(RIGHT(A1:A9,3)))),""000"")")
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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