VBA to find value MAX, MIN and LAST_DAY

excel_newbie86

New Member
Joined
Aug 1, 2020
Messages
17
Office Version
  1. 2016
  2. 2007
Platform
  1. Windows
Book1
ABCD
1File nameValue
2A12345-99902001-12345678-20200730-xx-y-zz.xlsx100
3A12345-99902001-12345678-20200731-xx-y-zz.xlsx120
4A12345-99902001-12345678-20200630-xx-y-zz.xlsx140
5A12345-99902001-12345678-20200630-xx-y-zz.xlsx141MAX
6A12345-99902001-12345678-20200620-xx-y-zz.xlsx101
7A12345-99902001-12345678-20200621-xx-y-zz.xlsx95
8A12345-99902001-12345678-20200829-xx-y-zz.xlsx99
9A12345-99902001-12345678-20200830-xx-y-zz.xlsx81
10A12345-99902001-12345678-20200831-xx-y-zz.xlsx80MINLAST_DAY
Sheet1


Hi all

I have data in sheet1 with column(A) is file name, column(B) is value

I want to have macro to do that:
- Find MAX value in coumn(B) then add "MAX" to column(C)
- Find MIN value in coumn(B) then add "MIN" to column(C)
- Find the last day in coumn(A) then add "MAX" to column(A)
the day in column(A) in character from 26 to 33 => With my data the last_day must be in file A12345-99902001-12345678-20200831-xx-y-zz.xlsx ==> last day is 20200831

Thanks./.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
See if this does what you want. Test with a copy of your data.

VBA Code:
Sub MinMaxLast()
  Dim lr As Long
  
  lr = Range("A" & Rows.Count).End(xlUp).Row
  With Range("C2:C" & lr)
    .FormulaR1C1 = "=IF(RC[-1]=MAX(R2C[-1]:R" & lr & "C[-1]),""MAX"",IF(RC[-1]=MIN(R2C[-1]:R" & lr & "C[-1]),""MIN"",""""))"
    .Value = .Value
    With .Offset(, 1)
      .FormulaR1C1 = "=IF(MID(RC[-3],26,8)-AGGREGATE(14,6,MID(R2C[-3]:R" & lr & "C[-3],26,8)+0,1)=0,""LAST_DAY"","""")"
      .Value = .Value
    End With
  End With
End Sub
 
Upvote 0
You're welcome. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,215,050
Messages
6,122,868
Members
449,097
Latest member
dbomb1414

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