Macros for hiding rows based on date

%3CLINGO-SUB%20id%3D%22lingo-sub-1861352%22%20slang%3D%22en-US%22%3EMacros%20for%20hiding%20rows%20based%20on%20date%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1861352%22%20slang%3D%22en-US%22%3E%3CP%3EIt%20seems%20it%20should%20be%20simple%20but%20I%20have%20spent%20a%20few%20days%20on%20this%20so%20am%20reaching%20out.%26nbsp%3B%20I%20am%20just%20learning%20Macros%20and%20am%20blown%20away%20by%20what%20it%20does%2C%20but%20this%20one%20situation%20is%20driving%20me%20crazy.%26nbsp%3B%20I%20have%20an%20Excel%20doc%20that%20the%20first%20sheet%20is%20entered%20by%20Admin%20Staff%2C%20then%20on%20the%20second%20sheet%20is%20the%20exact%20same%20info%20for%206%20columns.%26nbsp%3B%20This%20is%20the%20sheet%20that%20the%20Senior%20staff%20will%20be%20looking%20at.%26nbsp%3B%20What%20we%20want%20on%20the%20second%20sheet%20is%20that%20any%20row%2C%20with%20a%20date%20before%20%22today%22%20in%20Column%20F%2C%20be%20hidden%20so%20that%20the%20Senior%20Staff%20only%20see%20what%20is%20of%20a%20concern%20to%20them%20at%20this%20point.%26nbsp%3B%20We%20need%20to%20keep%20the%20info%20though%2C%20that%20is%20why%20there%20is%20a%20sheet%20one%2C%20but%20on%20sheet%20two%20they%20will%20only%20see%20staff%20with%20a%20date%20of%20today%20or%20later.%26nbsp%3B%20Also%20would%20like%20to%20have%20a%20macro%20that%20unhides%20these%20rows.%26nbsp%3B%20Would%20like%20to%20set%20up%20buttons%20or%20toggles%20so%20they%20are%20just%20clicked%20to%20update%20the%20information%2C%20but%20are%20able%20to%20unhide%20if%20needed.%26nbsp%3B%20i%20have%20tried%20multiple%20codes%20and%20am%20lost%20here%20as%20why%20it%20will%20not%20work%20for%20me.%20I%20know%20there%20are%20other%20simple%20ways%2C%20but%20using%20a%20button%20will%20help%20as%20Senior%20staff%20only%20want%20simple%20and%20fast.%26nbsp%3B%20Does%20anyone%20have%20suggestions%3F%26nbsp%3B%20Thank%20you.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1861352%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1861810%22%20slang%3D%22de-DE%22%3ESubject%3A%20Macros%20for%20hiding%20rows%20based%20on%20date%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1861810%22%20slang%3D%22de-DE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F860254%22%20target%3D%22_blank%22%3E%40MVelve%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWith%20your%20permission%2C%20if%20I%20can%20recommend%2C%20It's%20helpful%20to%20know%20your%20operating%20system%20and%20Excel%20version%2C%20as%20different%20approaches%20may%20be%20required%20depending%20on%20the%20version%20and%20OS.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENevertheless%2C%2C%20give%20this%20a%20try%20(untested%20but%20should%20work)%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EPrivate%20Sub%20Worksheet_Activate()%0ADim%20i%20As%20Long%0ADim%20heute%20As%20Date%0ASheets(%22Topics%20for%20the%20next%20meeting%20%22).Activate%0AFor%20i%20%3D%20ActiveSheet.UsedRange.Rows.Count%20to%201%20Step%20-1%0ARange(%22A%22%20%26amp%3B%20i).Select%0AIf%20ActiveCell.Value%20%26gt%3B%20date%20-%201%20Then%0AActiveCell.EntireRow.Hidden%20%3D%20True%0AElse%0AEnd%20If%0ANext%20i%0AEnd%20Sub%0A%0A'Please%20adjust%20according%20to%20your%20needs%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EThank%20you%20for%20your%20understanding%20and%20patience%3C%2FP%3E%3CP%3EI%20would%20be%20happy%20to%20know%20if%20I%20could%20help.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENikolino%3C%2FP%3E%3CP%3EI%20know%20I%20don't%20know%20anything%20(Socrates)%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E*%20Kindly%20Mark%20and%20Vote%20this%20reply%20if%20it%20helps%20please%2C%20as%20it%20will%20be%20beneficial%20to%20more%20community%20members%20reading%20here%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1861878%22%20slang%3D%22en-US%22%3EBetreff%3A%20Macros%20for%20hiding%20rows%20based%20on%20date%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1861878%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F722750%22%20target%3D%22_blank%22%3E%40Nikolino%3C%2FA%3E%26nbsp%3BThank%20you!%20Yes%20it%20did%20work%20except%20I%20used%20it%20to%20search%20in%20the%20F%20Column%20but%20it%20starts%20searching%20around%20row%201100%20-%20Is%20there%20a%20way%20to%20have%20it%20only%20search%20until%20the%20last%20row%20-%20which%20could%20change%20as%20information%20is%20added%20to%20the%20main%20sheet.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1861958%22%20slang%3D%22de-DE%22%3ESubject%3A%20Macros%20for%20hiding%20rows%20based%20on%20date%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1861958%22%20slang%3D%22de-DE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F860254%22%20target%3D%22_blank%22%3E%40MVelve%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EIt%20should%20look%20for%20the%20date%20and%20hide%20or%20unhide%20from%20there.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EWhat%20if%20a%20date%20in%20between%20ends%20before%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EIn%20the%20end%20anything%20is%20possible%2C%20it%20depends%20on%20the%20effort.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EShould%20it%20only%20take%20the%20last%20entered%20date%20in%20F%20and%20then%20work%20up%20according%20to%20your%20requirements%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EI%20don't%20recommend%20it%2C%20but%20if%20that's%20your%20wish%20...%20I'll%20try%20to%20prepare%20it%20for%20you%20(starting%20tomorrow%2C%20after%20church%20and%20after%20Bistro%20%3A).%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EI%20think%20I'll%20have%20found%20the%20time%20by%20the%20day%20after%20tomorrow%20%3A)).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22VIiyi%22%3E%3CSPAN%20class%3D%22JLqJ4b%20ChMk0b%22%3E%3CSPAN%3ETo%20be%20on%20the%20safe%20side%2C%20please%20describe%20to%20me%20step%20by%20step%20what%20the%20Macros%20should%20do.%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20your%20understanding%20and%20patience%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENikolino%3C%2FP%3E%3CP%3EI%20know%20I%20don't%20know%20anything%20(Socrates)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1862011%22%20slang%3D%22en-US%22%3EBetreff%3A%20Macros%20for%20hiding%20rows%20based%20on%20date%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1862011%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F722750%22%20target%3D%22_blank%22%3E%40Nikolino%3C%2FA%3E%26nbsp%3BThank%20you!%20The%20first%20worksheet%20is%20entered%20by%20Admin%20staff.%20and%20needs%20to%20be%20left%20as%20is.%26nbsp%3B%20The%20%22Summary%22%20sheet%20is%20the%20one%20we%20want%20to%20update%20and%20hide%20rows.%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EThe%20dates%20in%20column%20F%20will%20be%20the%20date%20that%20the%20worksheet%20%22Summary%22%20goes%20by.%26nbsp%3B%20The%20rows%20that%20are%20%22%26lt%3B%20Date%20-%201%22%26nbsp%3B%20in%20column%20F%20will%20be%20hidden.%26nbsp%3B%20Maybe%20another%20value%20to%20search%20would%20be%20that%20the%20Name%20has%20a%20value%20in%20it%20so%20that%20only%20the%20rows%20with%20a%20name%20and%20the%20dates%20will%20show%20in%20the%20Macro.%26nbsp%3B%20What%20is%20your%20recommendation%20to%20make%20this%20better%3F%20A%20button%20will%20be%20created%20so%20when%20it%20is%20pressed%2C%20it%20will%20update%20the%20sheet%20based%20on%20this%20macro.%26nbsp%3B%20What%20we%20want%20the%20Senior%20Staff%20to%20see%20are%20only%20the%20names%20of%20staff%20that%20are%20still%20not%20available%20for%20work.%20Another%20button%20would%20be%20created%20to%20unhide%20the%20rows%20if%20needed.%26nbsp%3B%20Is%20this%20enough%20information%20from%20me%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

It seems it should be simple but I have spent a few days on this so am reaching out.  I am just learning Macros and am blown away by what it does, but this one situation is driving me crazy.  I have an Excel doc that the first sheet is entered by Admin Staff, then on the second sheet is the exact same info for 6 columns.  This is the sheet that the Senior staff will be looking at.  What we want on the second sheet is that any row, with a date before "today" in Column F, be hidden so that the Senior Staff only see what is of a concern to them at this point.  We need to keep the info though, that is why there is a sheet one, but on sheet two they will only see staff with a date of today or later.  Also would like to have a macro that unhides these rows.  Would like to set up buttons or toggles so they are just clicked to update the information, but are able to unhide if needed.  i have tried multiple codes and am lost here as why it will not work for me. I know there are other simple ways, but using a button will help as Senior staff only want simple and fast.  Does anyone have suggestions?  Thank you.

10 Replies
Highlighted

@MVelve 

With your permission, if I can recommend, It’s helpful to know your operating system and Excel version, as different approaches may be required depending on the version and OS.

 

Nevertheless,, give this a try (untested but should work)

Private Sub Worksheet_Activate()
Dim i As Long
Dim heute As Date
Sheets("Topics for the next meeting ").Activate
For i = ActiveSheet.UsedRange.Rows.Count to 1 Step -1
Range("A" & i).Select
If ActiveCell.Value > date - 1 Then
ActiveCell.EntireRow.Hidden = True
Else
End If
Next i
End Sub

'Please adjust according to your needs

Thank you for your understanding and patience

I would be happy to know if I could help.

 

Nikolino

I know I don't know anything (Socrates)

* Kindly Mark and Vote this reply if it helps please, as it will be beneficial to more Community members reading here

Highlighted

@Nikolino Thank you! Yes it did work except I used it to search in the F Column but it starts searching around row 1100 - Is there a way to have it only search until the last row - which could change as information is added to the main sheet.

Highlighted

@MVelve 

It should look for the date and hide or unhide from there.

What if a date in between ends before?

In the end anything is possible, it depends on the effort.

Should it only take the last entered date in F and then work up according to your requirements?

 I don't recommend it, but if that's your wish ... I'll try to prepare it for you (starting tomorrow, after church and after Bistro :).

I think I'll have found the time by the day after tomorrow :)).

 

To be on the safe side, please describe to me step by step what the Macros should do.

 

Thank you for your understanding and patience

 

Nikolino

I know I don't know anything (Socrates)

Highlighted

@Nikolino Thank you! The first worksheet is entered by Admin staff. and needs to be left as is.  The "Summary" sheet is the one we want to update and hide rows.


The dates in column F will be the date that the worksheet "Summary" goes by.  The rows that are "< Date - 1"  in column F will be hidden.  Maybe another value to search would be that the Name has a value in it so that only the rows with a name and the dates will show in the Macro.  What is your recommendation to make this better? A button will be created so when it is pressed, it will update the sheet based on this macro.  What we want the Senior Staff to see are only the names of staff that are still not available for work. Another button would be created to unhide the rows if needed.  Is this enough information from me?

Highlighted
about searching around row 1100. Just change Range("A" & i).Select to Range("F2:F100" & i).Select, i think then search only 100 rows. Rest follows
Highlighted

@Nikolino Thank you!  That did not work for me but will keep working on it.  The best way to describe it is in the 2nd worksheet, if Column A2 ( or all of Column A) row 2 (multiple rows) has a value in it (the name) and Column F2 (all of column F2) row 2 (multiple rows) has a date earlier than today (<date) then hide the row.  Would also like to unhide if needed.  Hope this makes sense.

Highlighted

@MVelve 

Sry for the late answer, but the pastis in the bistro was very tasty, took a little longer :).

Here is a small suggestion for a solution. As far as tested on the quick, it works.

 

* I freed the file from useless entries, so it has become much smaller and more manageable.

 

Hope the proposed solution fits into your project.

File inserted.

 

Thank you for your patience and time.

 

Nikolino

I know I don't know anything (Socrates)

 

* Kindly Mark and Vote any reply if it helps please, as it will be beneficial to more Community members reading here.

Highlighted

@Nikolino Thank you for your work!  It did not work  - it takes away the last few rows and not any of the rows which "14 day return to work" column is before "todays" date.

Highlighted
Work with the advanced filters in columns. When I have something I'll send it to you. Thank you for your patience and time. Nikolino
Highlighted
If you don't mind me asking, why have the second worksheet that just links to the first worksheet? It creates a very large file that is slow to open (50MB file versus 17KB). Also, if someone inserts a row on your data worksheet, it will be missing from your summary (the newly inserted row will not be linked to your summary worksheet unless you recopy your formulas).

Why not just filter the table on the data entry tab (column k). If you click the drop arrow and select "date filters," there are a lot of standard options (year, month, week) and custom options (before, after, between - with a date picker calendar) available.

I'm having a hard time seeing how the macro is going to save much time over just using the filter - especially as the file grows.