Copy range to other worksheet if A1 contains specific word - vba

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.

Related

Querying data from quite old IBM iseries AS400 DB2 (date format issue)

I am quite a newbie in querying data from databases and now I am currently having an issue with date format in very old (I don't know exact version) IBM iSeries AS400 DB2 database. My problem is that the date is stored in this DB in three separate columns as whole number (column day + column month + column year) and I need to connect to this DB via ODBC in Excel and filter just a few rows according to desired date span (e.g. from 1st December 2019 until 31st December 2019). In this case I don't want to use PowerQuery to do all the modifications, because the complete table has millions of rows. I want to specify the filter criteria within SQL string so the PowerQuery doesn't have to load all the rows...
My approach was following:
I've created 6 parameter cells in Excel sheet where I simply defined Date From (e.g. cell 1 = '01', cell 2 = '12' and cell 3 = '2019') and Date To (same logic for parameter cells 4, 5 and 6). Then I mentioned these parameter cells in SQL string where I defined:
(Day >= Parameter cell 1, Month >= Parameter cell 2, Year >= Parameter cell 3)
and
(Day <= Parameter cell 4 etc.)
This worked quite good for me, but only when I liked to export just a few hundreds of lines within the same year. But now I am facing to an issue when I like to export data from 1st December 2019 to 31st January 2020. In this case my "logic" doesn't work, because Month From is '12' and Month To is '01'.
I've tried another approach with concat SQL function to create text column like '2019-12-01' and then convert this column to datetime format (with cast to varchar8 first), but it seems that this approach doesn't work for me, because everytime I get an error which says: "Global variable DATETIME not found".
Before I post you some of my code, could I ask you for an advise, if you can think of a better solution or approach for my issue?
Many thanks and have a great day :-)
A simple solution would be
select * from table where year * 100 + month between 201912 and 202001

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.

Macro for sorting and Sumif

In a worksheet, I have 5 columns, 1st column contain the file name. I have to split the file name in team,branch,location and week wise in preceding columns. after that have to apply filter and first filter on week from Oldest to newest then on location A to Z. I have 3 weeks data in each report. At the end of the last row, I want to add 3 more row of respective weeks and sum the respective weeks data.i.e eq. for 22-May-17, the next column should add only the data of the row of the same date.
table image

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

Excel sub to fill out a table averaging data of another sheet

I am having issues to get data from several time stamps into usable data.
I am trying to fill out a table which the first of every column is a month (January --> December) and the first of every row is an hour of day (00 --> 23).
The table is to be filled out by averaging data from another sheet which consists of a timestamp (i.e. 2011-01-01 0:00) and an amount (i.e. XXXX.XX).
My current logic is this:
Get Cell Number (i.e. B2)
Get Hour and Month allocated to cell (i.e. 00 and January)
Loop through data and Average data of said month and hour from other sheet excluding weekend days
Can anyone help me figure out the coding for this?
Need sample data and also what you have tried so far. You can achive the same using Countifs and sumifs.
So a given cells will be sumifs/countifs to get the average time for the given hour and for the given month.
To know more you can use excel help for the given formulas.