Find a max value across multiple sheets and return sheet name

XLgeekette

New Member
Joined
Aug 20, 2013
Messages
4
I would like to find the largest value across multiple sheets and return the sheet name where the value is located in. The issue is that each week a new sheet is added so I can't create a static list of sheet names. The data are located in the same cell across sheets in cell B10. I have hidden blank sheets called "First" and "Last" at the beginning and end of each week's sheet ("Week 1" -- "Week N") so I can use the formula MAX(First:Last!B10) to get the largest value. How can get the sheet name where it's located when the sheets are continuously added? Thanks.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Good job on using the formula to span multiple sheets. I just discovered that one last year from somebody else on this site. Unfortunately it won't return which sheet it came from. I suggest a VBA routine for that.

Code:
'Provide the name of the first blank hidden sheet
'Provide the name of the last blank hidden sheet
Function GetShtNameWithMax(First As String, Last As String) As String
  Dim TWB As Workbook
  Dim Sht As Worksheet
  Dim Between As Boolean
  Dim MaxVal As Double
  Dim MaxSht As String
  Dim m As Double
  
  Set TWB = ThisWorkbook
  
  For Each Sht In TWB.Worksheets
    If UCase(Sht.Name) = UCase(First) Then
      Between = True
    ElseIf UCase(Sht.Name) = UCase(Last) Then
      Between = False
      Exit For
    ElseIf Between = True Then
      m = Application.Max(Sht.Range("C:C"))
      If m > MaxVal Then
        MaxVal = m
        MaxSht = Sht.Name
      End If
    End If
    
  Next Sht
    
  GetShtNameWithMax = MaxSht
    
End Function
 
Upvote 0
Jeffrey, thanks for the code, but it didn't work. After running it I just get a blank in the cell. Any thoughts on why it's not working?
 
Upvote 0
Hi,

If, as you suggest, your sheets are all consistently named "Week 1", "Week 2", etc.:

="Week "&MATCH(1,FREQUENCY(MAX(First:Last!B10),First:Last!B10),0)

Regards
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,206
Members
452,618
Latest member
Tam84

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