Excel - display only columns with specific month and year - vba

Need help!
I have put into row 6 in Excel dates starting from 1st November, 2016 (Cell F6) to 31st December, 2017 (Cell PO6).
Cell B1 shows drop down list of months and cell B2 shows years.
I need a tip on how to set formula which will allow me to show only columns of month and year which are chosen in cells B1 and B2. For Example, if i choose November 2016, only columns F:AI will be visible, while columns AJ:PO will be hidden.
Please provide suggestions on how can this formula be formatted in different way, if you have suggestions.

You should write a VBA code combining if...then with
Worksheets("Sheet1").Columns("C").Hidden = True
The if...then guide is here and the hide column guide is here.

Related

VBA to filter all months w/ year in date column

I am on this project that I need to filter out all the months with year in the date column. For example, all the January 2017 dates are filtered out and copy to new sheet, all February 2017 dates are filtered out and copy to new sheet, and so on. Is it possible in VBA? I don't have code yet. Thank you in advance.

Changing the value of the other Cell base on the month you entered

So I have an Excel file with 2 sheets with the name of YEAR sheet and monthly report Sheet, Is that possible to change the value of F21:F29 of Monthly report Sheet base on the date or current date today., for ex. Today is February, the data that will be place on F21:F29 of Monthly report sheet is the February Column or the F21:F29 of the YEAR Sheet., and when the current month is March the data that will be place on F21:F29 of Monthly report sheet is the March Column or the G21:G29 of the YEAR Sheet.
Thank you so much Guys, GoodBless
Based on your given screenshot put below formula to F21 cell of Monthly Report Sheet then drag and down as need.
=IFERROR(INDEX('YEAR Sheet'!$E$21:$P$32,ROWS($E$21:$E21),MATCH(LEFT($F$3,3),'YEAR Sheet'!$E$19:$P$19,0)),"")
Note: If data starts from different cell in YEAR sheet then you have to modify formula to adjust will data ranges.
Use INDEX MATCH. As long as the cells with the months in are all formatted as dates it'll work
in the code pane of your "monthly report Sheet" worksheet place the following code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.address = "$G$3" Then Range("F21:F29").Value = Worksheets("YEAR sheet").Range("D21:D29").Offset(, Month(Range("G3"))).Value
End Sub

Copy range to other worksheet if A1 contains specific word

I have 2 worksheets:
1st - for monthly data, where I collect data only for 1 month (1...12)
2nd - annually data by months (12 tables for each month)
I need macro which will copy data from monthly sheet to annually sheet according to month.
For example, if it`s September it will copy to September table in annually sheet.
If October to October table in annually sheet and so on.
How could I implement it using macro (want create button: click and copy).
The macro will need to include a CASE statement with 12 options (one for each month). Prior to reaching this CASE statement, you need to define a variable that will represent the month (e.g. using current date).
Each option within the CASE construct will copy from a specified sheet into a specified table (here I'm assuming that the structure of the monthly table are known and static).
An alternative approach would be to have the CASE setting the SOURCE sheet and the target range within the annual sheet. This would be a shorter piece of code using a common COPY block.

Excel how to set a given value to date ranges

I need to automatically set a value of 8.45 hours work for the winter schedule (01 October till 15 June) and 6 hours work for a summer schedule (16 June till 30 September) for a time sheet done in Microsoft Excel.
The equation I am trying is the following:
=IF(AND(DATE($G$1,6, DAY(15))>=(DATE($G$1-1, 10, DAY(1))));(DATE($G$1,6, DAY(15))<A8;8.45;"")
But this keeps on returning formula errors and this still omits the rate value for the summer schedule.
$G$1 is the year that is manually inputted for the yearly time sheet.
A8 is the current date.
Any guidance into this equation would be appreciate.
With best regards Fab
Edit
Thanks DirkReichel, Scott Craner, Alex Bell, Michael Uray for your great intervention.
I tried all the suggestions but some returned a =VALUE error and some did not omit the winter schedule as from the 1 October ->
This is the correct equation:
=IF(AND(DATE($G$1,9,30)>=A8,DATE($G$1,6,15)<=A8),6,8.45)
The equation checks the current date being A8 and checks if it falls withing the summer period (date range). If current date falls within the summer period the value is returned to 6, if the current date falls outside the summer period, it returns a value of 8.45.
Thanks to all that guided.
Depends on the regional settings, you may use comma "," instead of ";" as shown in the following example:
=IF(AND(NOW()>DATEVALUE("6/15/2016"), NOW()<DATEVALUE("9/1/2016")),6,8.45)
Hope this may help.
Try this:
=IF(AND(DATE($G$1,6,15)>=A8,DATE($G$1-1,10, 1)<=A8),8.45,6)
The following solution should work for you:
A1 is the date which gets checked, the formula is placed in B1.
On this way you can pull down a list of dates and formulas in your sheet.
=IF(AND(A1>DATE(YEAR(A1),6,15),A1<DATE(YEAR(A1),8,1)),6,8.45)
It checks if the data is in the range of YYYY-06-15 and YYYY-08-01 and sets then the output to 6, or if it is not in this range to 8.45
I did test it with e German Excel Version with the following formula and I translated it then manually in Notepad to the English formula version.
=WENN(UND(A1>DATUM(JAHR(A1);6;15);A1<DATUM(JAHR(A1);8;1));6;8,45)
I hope my formula translation will work for you in the English Excel version.

Conditional formating based date range in VB

Have a column of dates which i need to compare to a specific time of the year, which establishes what calculation needs to be applyed then depending on the outcome apply conditional formating to highlight an adjcent cell, but need to remove the YY element as the contents spans multiple years.
if the date in A1 is between 1st Jan & 14th Mar use -8
if the date in A1 is between 15th Mar & 15th Oct use -17
if the date in A1 is between 16th Oct & 31st Dec use -8
Then deduct the above value from B1 to give a target
for each row (from 3 onwards)
if the target is < the value in n then change background orange in f
and repeat.
Any help would be greatly welcome, thank you.
Is this Excel? If so, then it has all kinds of conditional formatting stuff built right into the application; no programming needed.