Can anyone suggest a vba to hide columns based on todays date. I have 12 months of data but only want to show current month, last 3 months or last 12 months based on checkbox
I would suggest providing a bit more information in regards to the structure of your worksheet/data. That would make it easier for everyone to suggest solutions rather then working on assumptions.
Anyway, assuming you have dates in 1st row from column B to D as (1-1-21, 1-2-21, 3-1-21), try the following
VBA Code:
Sub hide_Col()
Dim rng As Range
Set rng = ActiveSheet.Range("b1:d1")
For Each cell In rng
If Month(cell) = Month(Date) Then
Columns(cell.Column).Hidden = True
End If
Next cell
End Sub
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.