0

looking through the forum and can't find what I need. I have 100+ sheets with unique sheet names and data in column B. Column B will contain various END DATES. some sheets will have 1 or 2 end dates, others have upwards of 30 end dates. . I would like to create a summary page containing a table that will update itself to show all sheet names that have END dates in column B expiring within the next 30 days. is this something that requires coding? or use of the excel indirect formula with maybe a vlookup wrapped around it?

4
  • Seems there's nothing to do with VLOOKUP. You can loop through the Worksheets() collection for checking each sheet. Commented Nov 7, 2017 at 17:58
  • What version of Excel do you have. [Cue voiceover: ] "This sounds like a job for PowerQuery" Commented Nov 7, 2017 at 20:49
  • @jeffreyweir excel 2010 Commented Nov 7, 2017 at 21:58
  • Okay. In 2013 and 2016 there's something called PowerQuery aka "Get and Transform" that makes it trivial to merge together data from different sources (including tabs in the one workbook) and then create a PivotTable out of them. In your case, you could then filter the PivotTable to show end dates within the next 30 days. Commented Nov 7, 2017 at 22:05

3 Answers 3

2
Private Sub ChkEndDates()
    Dim ws As Worksheet
    Dim cell As Range
    Dim rowCount as Long
    For Each ws in Worksheets
        If ws.Name <> '"summary page" Then
            rowCount = WorksheetFunction.CountA(ws.Range("B:B"))
            For i = 1 To rowCount
                If (ws.Cells(i, 2).Value - Date < 30) And (ws.Cells(i, 2).Value > Date) Then
                    MsgBox ws.Name
                    'And maybe push into the summary page
                End If
            Next i
        End If
    Next ws
End Sub
Sign up to request clarification or add additional context in comments.

4 Comments

Using rowCount assumes that data starts in row 1 and has no blanks. Better to either reference ListObjects (which of course requires each data area to be turned into a Table...something I would take the trouble to do using a one-off bit of VBA) or by selecting the bottom cell in each column and using .End(xlUP) to select the last row of data.
thank you all. I will see what I can come up with. thanks for the input!
I tried this code. getting a "Type mismatch" error. I think it is because not all the data is column B is in a date format. So maybe we need to add a check to only run the loop if the data in column B is a date. there are row headers and titles etc also in Column B.
Sure, you didn't show any data you have. Therefore all I can do is giving you a general method, and you have to adjust it according to the data by yourself.
2

Neither VLOOKUP nor INDIRECT are required for this problem.

Assuming your dates in the B columns are in Excel's serial number format, this formula will calculate the amount of cells in the B column of Sheet2 that are within 30 days from today's date:

= SUMPRODUCT((Sheet2!B:B>=TODAY())+0,(Sheet2!B:B<=(TODAY()+30))+0)

You can just duplicate this formula for however many sheets you need, e.g.

= SUMPRODUCT((Sheet2!B:B...))+SUMPRODUCT((Sheet3!B:B...))

EDIT

Per @Jeeped's comment, it is recommended to narrow down this range (B:B) just to the end of your data. (e.g. if you have at most 30 rows of data, change to B1:B30)

2 Comments

Might want to knock down those full column references or switch to countifs.
@Jeeped Thanks, good call, just added to my post to narrow down the B:B range.
2

For completeness, here's how you would do this using PowerQuery/Get & Transform if you had Excel 2013 or later.

First, you would turn each of the data areas in your workbook into Excel Tables (aka ListObjects), by selecting them and either using the Insert>Table command from the ribbon, or simply by using the keyboard shortcut [Ctrl] + [T]. Ideally you would give them all a name that denotes what they are. (I've used the prefix "Input_" and then a running count, because later this 'handle' will help me to ignore any Tables that I don't want in my end result, simply by seeing if it's name is prefixed with "Input_").

Then from the Data tab, select New Query>From Other Sources>Blank Query:

enter image description here

A mysterious looking UI called the PowerQuery window will open with nothing much of interest in it. If you type =Excel.CurrentWorkbook into the formula bar and press Enter, then a list of the various Tables in your workbook will populate in that window, as shown below. And if you click that twin arrow icon to the right of the Content column, a menu will appear that lets you expand those tables to include the actual columns in each of them, and bring them into the PowerQuery window:

enter image description here

And here's how that data dump looks, when you push OK:

enter image description here

This next bit is only required if you have other Tables in your workbook already that you don't want to show in your end mashup. In the screenshot below, I'm filtering the result set to only include tables with the Input_ prefix:

enter image description here

enter image description here

And then I'm going to change the data type of that DateTime column to a simple Date, by selecting the column concerned, and then choosing Data Type>Date from the Transform tab.

enter image description here

Then I'm going to select Close and Load To from the menu at top right:

enter image description here

..and then select the "Only Create Connection" and "Add to Data Model" options from the resulting dialog:

enter image description here

Now back in Excel, I create a PivotTable, and leave the "Use this workbook's Data Model" option checked:

enter image description here

...which brings up a slightly different looking PivotTable Fields List than you usually see:

enter image description here

I now add the Name (Table Name) and End Date fields to my Pivot, and set a date filter to just show dates within the next 30 days:

enter image description here

enter image description here

enter image description here

And here's the end result, a PivotTable that shows just those tables with end dates within the next 30 days:

enter image description here

The beauty of this approach is that if you later add more tabs with more input tables, then provided you prefix them with "Input_" then they will automatically appear next time you refresh the PivotTable. And furthermore, instead of having a report that merely tells you which tabs have applicable End Dates, the PivotTable also tells you which individual records in those tabs are involved.

There's more stuff I would do along the way that I haven't shown, such as give the columns friendlier names by ditching the "Content." suffix, and I'd probably write a simple macro to automatically refilter the PivotTable based on 30 days from the current date. But this at least shows you the benefits of upgrading to Excel 2013 and using PowerPivot/Get and Transform to radically automate tasks such as this.

2 Comments

wow thanks for all that. the things excel can do baffle me. had no idea about a power query
You can actually use it in Excel 2010, but you need to download and install it, and I'm not sure whether it is as up to date as the version in later versions. In later versions it is baked in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.