Using VBA to hide rows based on what month you specified.

figuare9

Board Regular
Joined
Oct 23, 2017
Messages
118
I have a bunch of data between A12:T1499


I have a bunch of dates starting at the first of the year through the entire year in Column F. Called "Date Order Received" F12:F1499

These are the dates that I'm trying to use to "sort".

I have 12 command buttons that have each month on them. So what I'm trying to do is be able to click on the "January" button, and have excel hide all rows that don't have January in the date order received. This way it should only display January Orders. And so forth, for each month.

So in a nutshell, Search F12:F1499 for any month that has January, and hide every row that doesn't include these months.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Are your buttons forms control buttons, shapes or activeX buttons?
If so have you changed the name of the button or just the caption
 
Upvote 0
Theyre activex command buttons. Each button has a name of the full month e.g. "January" and they have a caption of the same name.
 
Last edited:
Upvote 0
In that case try
Code:
Private Sub January_Click()
   Range("A11:T1499").AutoFilter 6, [COLOR=#ff0000]21[/COLOR], xlFilterDynamic
End Sub

Private Sub February_Click()
   Range("A11:T1499").AutoFilter 6, [COLOR=#ff0000]22[/COLOR], xlFilterDynamic
End Sub
Just add 1 to the value in red for each month as shown
 
Upvote 0
Oh, before i forget, i also have a button for "show all". Based on what i seen here, would i just keep that red value at "21" for that then? After i sort everything by month how do i get it back to normal?
 
Upvote 0
The show all button would need to be
Code:
Private Sub ShowAll_Click()
   Range("A11:T1499").AutoFilter 6
End Sub
 
Upvote 0
Fluff,

This was great! Thank you VERY much for the help! It's crazy how simple that was! I need to learn filters more!!

So, I have 6 more buttons.. Maybe you could give me a hand with them as well?

I have "show only completed" & "show only due orders"

[Show Only Completed] (Order Progress) is under Column J. J12:J1499 When an order is completed, we'll enter "Completed" here. Otherwise, this stays blank

[TABLE="class: grid, width: 150"]
<tbody>[TR]
[TD="align: center"]Order Progress[/TD]
[/TR]
[TR]
[TD="align: center"]Complete
[/TD]
[/TR]
[TR]
[TD="align: center"]Complete[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD="align: center"]Complete[/TD]
[/TR]
[TR]
[TD="align: center"]Complete[/TD]
[/TR]
</tbody>[/TABLE]


[Show Only Due Orders] would just work off the order progress in Column J.. If it's not "Completed" then it would be a due order. So If it's blank In column J, we'd display these..

Then, I also have 4 more buttons

[Due in 2+ Weeks]
[Due in 1-2 Weeks]
[Due In 1 Week Or Less]
[Late Orders]

I use a helper column for these to make it easy.. I have a date formula in Columns Q, R, S, & T that will put "YES" Or "No" depending on the order status against today's date.
If Column Q has a "YES" then it's [Late Orders]
If Column R has a "YES" then it's [Due In 1 Week Or Less]
If Column S has a "YES" then it's [Due in 1-2 Weeks]
If Column T has a "YES" then it's [Due in 2+ Weeks]
 
Last edited:
Upvote 0
Use
Code:
Range("A11:T1499").AutoFilter 10,"Completed"
for the completed button, and
Code:
Range("A11:T1499").AutoFilter 10,"<>Completed"
for the not complete
For the others just change the field number (the 10 in the above code) to match the column & filter on "Yes"
 
Upvote 0
Thank you soo much for this! Incredible help. I really appreciate it! You're amazing! I'm going to look further into learning more of this.. Can't believe I haven't used it much prior to this.. :)
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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