vlookup to pick the nearest date lesser date from the reference cell - vba

I required your support,
I have a datasheet (Sheet1) which is having product details and its dates which are been imported. Another sheet (Sheet2) which are also having product details and its dates which are been exported by the seller. Both the sheet dates might not be equal nor the total no. of rows will be the same.
I wanted to understand if a Vlookup can compare the dates of sheet 1 & sheet2 for each product keeping the imported dates of sheet 1 as a reference and pull the nearest lowest date from the sheet2 "created date"
Sheet 1 is having the data which is from imported data
Sheet 2 is the date which shows the actual export from the seller
So now I need to do a comparison for the Product bearing (cell A2) from Sheet 1, which is having the imported date as of 10/22/2019. Comparing to the next Sheet2 (Image 2 ) for the same product bearing which is having the created dates as 10/18/2019, 11/08/2019,10/16/2019.
The formula should now pick a date which is nearest lesser to the imported date which is in the sheet1. in this case, formula to pick the date 10/18/2019.
I tried to sort the data to lowest to highest and highest to lowest, but v-lookup results were not always right. I tried to insert the IF condition resulted in no luck.
It would be very helpful if you all share some insight into this case.
Thank you for reading the above case.

Use AGGREGATE:
=AGGREGATE(14,7,B2:B100/((A2:A100="Bearing")*(B2:B100<=Date(2019,10,22)),1)

Related

how to group rows based on a dates in a single column

I have a range of date (A1:CY7026) with a column for start dates. this column has a large amount of repeated dates within it. i need these dates group together based on the working week they are located in (eg. all values reading 16/7/18 - 22/07/18 would be one group and the following week would make up another).
Use below in B2 cell (Suppose you had a header column) and drag to the rest. Sort to obtain the desired result.
=CONCATENATE(YEAR(A2),"-",WEEKNUM(A2))

Calculate matrix of values based on column and row totals

I have data that is broken into group totals (rows) and month totals (columns). I need to take the totals and calculate a value for each month within each group. From my screen shot I can find an monthly cell value for the quarter total with the formula
=INT($F3/3); this would ensure that all rows total correctly but does not address the requirement for all columns to total correctly.
For the screen shot I manually added the values to visualize the desired outcome
Group Calculation: (Jan+Feb+Mar)=Q1 group total
Month Calculation: (Group1...Group6)+Inventory = Monthly Total
In the "current result" screen shot the values total correctly by groups however the result is incorrect by month. For example 'Jan' totals to 159.
Current Result
I'm looking for assistance in a formula or vba that would allow the monthly values to total to the group and month total.
Desired Result
It sounds like you are looking to recreate a matrix from the totals of its rows and columns.
First, you need to remove the Inventory totals from the column totals, as those figures do not need to be calculated.
Then, you can get quite close to the answer with the formula =ROUND(RowTotal*ColumnTotal/OverallTotal,0). In this case, the formula in cell B2 would be =ROUND((B$8*$E2)/$E$8,0)
However, since there is rounding involved, you will notice that the values do not add up perfectly. For a matrix this small, your best bet would be to manually fix the problem values. To do so, add formulas to check which columns and rows are improperly totaled. Your check formulas should subtract the totals of each row and column from the desired row and column total. This reveals that cell B3 is the problem, as both column B and row 3 are misaligned.
You can change cell B3 to 48, which will then ensure that all columns and rows total properly. If you had a much larger matrix to solve, you could write some VBA code to automate the check of each column and row.

If particular cell is NOT BLANK copy down FORMULA from above cell

Basically I have the following formulas:
Column J: =IF(ISNA(VLOOKUP(I2,CCG,1,FALSE)),"Out of Area",VLOOKUP(I2,CCG,1,FALSE))
Column K: =INDEX(ResponsibleAgency,MATCH(N3,LeftLookup,0),MATCH(J3,TopLookup,0))
Column L: =IF(ISNA(VLOOKUP(N3,PPLookup,2,FALSE)),"Missing F Code",VLOOKUP(N3,PPLookup,2,FALSE))
Column M: =IF(ISNA(VLOOKUP(N3,PPLookup,3,FALSE))," ",VLOOKUP(N3,PPLookup,3,FALSE))
Basically, I only want these formulas to activiate provided that column A is populated with a date. If there is no date in column A, I want the cells to remain blank.
Is this possible?
Technically speaking, it is not possible to tell if cell contains a date or not in strict sense.
In Excel dates are in fact numbers representing number of days since January 1, 1900. I.e. today is 42066. It's the formatting that makes those numbers look like dates to user. If you pass a cell containing a date to any formula, it receives this number.
As a workaround, you can check if the cell satisfies two conditions:
It is a number.
It falls into some date range that makes sense.
For example, if your column contains goods delivery dates you usually don't expect them be previous century or 50 years into the future.
So you can wrap your formulae into something like this:
=IF(ISNUMBER(A1),IF(AND(A1>=DATE(2014,1,1),A1<=DATE(2015,12,13)),[LOGIC_IF_CORRECT_DATE_HERE],""),"")
Being said, it's still a workaround.

Excel, automatically updating variable in IF statement based on reference cell?

I have a sheet that needs to be updated monthly with a formula that needs to change with the month.
This is the formula: =IF($S3=AI$1,[#July],0)
The check is to make sure my values go into the correct category. After the category is determined correct, I need to take the month's values by referencing the month column in my table.
Question: Is there any way to make it so when I change the month somewhere, I can make the formula essentially move over a column to take the new month's values?
Note: I also have a similar case where instead of taking the month values verbatim, I'm summing the year's values til said month.
So I assume you have a table with column name January to December.
You can do this in at least two ways (I assume your month number is in cell A1)
Explicit: (in case these columns are not in order or adjacent to another)
=CHOOSE(A1,[#January],[#February], ... ,[#December])
Implicit: (if the months are next to each other:
=INDEX(TableName[#[January]:[December]],A1)
Obviously, I'd recommend the second option, if applicable.
If you want to sum from januar to the current month, you can use this little know trick/syntax:
=SUM([#January]:INDEX(TableName[#[January]:[December]],A1))

Filter rows by date (A column) and write sum (C column) to field in another sheet

I have two sheets in Google Spreadsheet document. The first one has columns Month, Income, Expense and Profit (A,B,C,D respectively) and in each row expense value should be calculated based from filter (I think) from another sheet called Expenses.
The Expenses sheet contains columns Date, Name and Price.
So, what I need is to write formula to filter only expenses for specific month, to sum all prices in those rows and to write that value to C column (row for that month) in first sheet.
You can see this example and please help me out to solve this.
This is a formula that can be filled down (I have entered it in F2):
=ArrayFormula(SUMIF(TEXT(Expenses!A$2:A;"MMMM");A2;Expenses!C$2:C))
This is a formula that will automatically populate results down the column (I have entered it in G2):
=ArrayFormula(IF(LEN(A2:A);SUMIF(TEXT(Expenses!A2:A;"MMMM");A2:A;Expenses!C2:C);IFERROR(1/0)))
And this formula will take the year into consideration; I have entered it in J2, referencing month-year strings in I2:I:
=ArrayFormula(IF(LEN(I2:I);SUMIF(TEXT(Expenses!A2:A;"MMMM yyyy");I2:I;Expenses!C2:C);IFERROR(1/0)))