VBA get max value from right of cells in range

dave2018

Board Regular
Joined
Mar 20, 2018
Messages
223
Hi, I'm writing this from a cellphone so I can't upload the data, but I have a column which has the following values (I will type this in array format, without the curly brackets): Bunk1;Bunk1;Bunk2;Bunk8;Bunk5;Camper;Bunk6;Bunk6;Nurse;Bunk7

I need the maximum value of a bunk, in this case the number 8, returned through a sub or function.

I don't think any values other than the ones starting with bunk will have numbers, such as nurse1, but I need to anticipate that, so the code gets the max of only the bunks.

Keep in mind that bunk10 may exist, so u can't just extract the right-most value. There may be double digits.

Thanks all!
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
I wasn't sure if you really need vba or whether you thought that was the only/best way?
Is this worksheet formula any use?

Excel Workbook
AB
2Bunk623
3Bunk
4Nurse88
5Bunk23
6Bank5000
7200
8
9
Max
 
Last edited:
Upvote 0
Hi, I do need vba. It's part of a bigger sub that I'm working on. Thx.
Then see if you can extract what you want from this:
Code:
Sub MaxWithText()
  Dim TextMax As Double
  
  Const LeftText As String = "Bunk"
  
  With Range("A2", Range("A" & Rows.Count).End(xlUp))
    TextMax = Evaluate(Replace(Replace("aggregate(14,6,replace(#,1,4,"""")/(left(#,4)=""@""),1)", "#", .Address), "@", LeftText))
  End With
  MsgBox TextMax
End Sub
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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