Excel - Change column headers based on dropdown selection - excel

I am building a 12-month cash flow forecast and I want the user to be able to choose the start month from a dropdown. This will then change all the column headers. I have set up a dropdown, which now returns the month position in the built in array i.e. selecting Aug, returns month 8. What’s the best way to get 8=Aug?
Thank you for looking.

If you have full date (yyyy-mm-dd) you can format header to display month, by setting mmm non-standard format.
Also, you can define list of months and use CHOOSE() funcion, which returns given position from a list.
Excel choose funcion

Related

Pivot Table - How do I make 'base item' for 'difference from' dynamic using vba?

I am attaching the macros, and desired result as an image.
So, I am running a macro to find differences (amounts) between dates that are selected from the slicer, using 'previous' as the base item in 'difference from' and it works perfectly. Now, I want to run another macro where the difference should be from the oldest of the selected dates. I hardcoded it once with a set of dates where the oldest date will always be 31-12-2021. But if I want to compare the data from 2021 then I need to find differences from 31-12-2020, basically the end of previous year. How do I make this base item dynamic so that it's either last end of year date or the oldest chosen date if someone is manually choosing the dates from the slicer?
My Macros
The desired pivot table result
Can I have the user enter the oldest date in a cell and have the vba code refer to that cell or something?
Any help would be appreciated. Thanks!

Formula to calculate DATE as TEXT

I have searched online and in forums but can´t find any solution for this.
I want to calculate date as TEXT in Sharepoint list with calculated fields.
It works to calculate well with the formula below, but it prints the date like this "2018-07-06T22:00:00Z"
=IF(ISBLANK([Contract Start]);"";DATE(YEAR([Contract Start]);MONTH([Contract Start])+[ContractLength];DAY([Contract Start])))
I have tried the following formula, and it gives me the date in the format i wish "2018-07-06" but i can´t get it to add months from column [ContractLength] to the date.
=IF(ISBLANK([ContractStarts]);””;CONCATENATE(TEXT([ContractStarts];"yyyy");"-";TEXT([ContractStarts];"MM");"-";TEXT([ContractStarts];"dd")))
So I need help with a formula that adds the specified number of months from the [ContractLength] column to the start date [ContractStarts] column in the SharePoint list, and print it as TEXT so we get the date printed "2018-07-06".
Thanks in advance!
I'm not quite sure what you mean with "calculate date as text". If you mean you want to show the result as text, not a date, then you can use this formula.
=IF(ISBLANK(ContractStarts);"";TEXT(DATE(YEAR(ContractStarts);MONTH(ContractStarts)+ContractLength;DAY(ContractStarts));"yyyy-mm-dd"))
Or, if you want the result to be a date, then this formula works fine, too, but you need to select "Date" as the data type of the calculated column and tick the button for Date only.
=IF(ISBLANK(ContractStarts);"",DATE(YEAR(ContractStarts);MONTH(ContractStarts)+ContractLength;DAY(ContractStarts)))
The screenshot below shows both formulas at work in the SharePoint list.

Excel VBA - looping formula array and pass it into variables

i'm working on an exercise where i have the following columns
first column for primary key
second column for open date
third column for open price
fourth column for close date
fifth column for close price
The primary key will repeat multiple time due to different open date and close date through the year. So currently i'm able to use advance filtering function through vba and get an unique record of primary key, but i also need to find the min and max of open date and close date based on each primary key and identify the open price based on min of open date and closed price based on max of closed date.
can anyone help? because i can solve this with array formula within excel but no luck of converting each array formula into vba and pass it to variables.
sample list:
expected result:
array formulas used:
=MIN(IF(A1:A70926=J2,B1:B70926))
=INDEX(C:C,MATCH(1,(J2=$A:$A)*(M2=$B:$B),0))
=MAX(IF($A:$A=J2,$B:$B))
=INDEX(F:F,MATCH(1,(J2=$A:$A)*(O2=$B:$B),0))
I am not entirely clear on which max and mins you want but provided you convert your date strings to actual dates, you can use a pivottable to get any combination of max, mins from the date e.g.
With the above:
Helper column F has the formula in F2, which autofills down as source is set up as Excel table.
=DATE(LEFT(B2,4),MID(B2,5,2),RIGHT(B2,2))
This generates an actual date.
Pressing Ctrl+T, with a cell selected in the range, convertes the data into an Excel table, then Alt+N+V generates a pivottable from that table.
Then arrange as you wish. For example, with date in the rows area you can easily then select max and min dates via filter. You can have ticker either as a page field filter or add to the rows in front of the converted date. And then add open and closed fields to the values area. You can add the same field more than once. Make sure to right click on the first time you add and do value > field settings > min
Repeat for adding the same field and set as max.
Close up on pivot:
If you want the all time max and min value, simply remove the date field from the rows:
If you want for a particular year, when date field is in the rows area, right click and use the date filters functionality:

Automatically updated calendar using formulas

I have a table with information about various events (1 row = 1 event). One of the columns in the table holds the date of the event in the format "YYYY-MM-DD".
The calendar in which I am trying to make the events appear automatically have one cell with information about year and month in the form "YYYY-MM-01". The day of the month is held in a seperate cell in the calendar on the format "D"/"DD".
If the year, month and day match, I want the acronym (held in a column in the table of events) of the event to be returned by the function and displayed in the calendar.
My first thought was to use a function like this:
=IF(AND(YEAR(Table13[Start Date])=YEAR($A$1);MONTH(Table13[StartDate])=MONTH($A$1);DAY(Table13[StartDate])=DAY(F3));Table13[Acronym];" ")
but I realised looking thru the table like that wont work.
Any ideas on how I can proceed? I hope the explanation isnt too messy.
Link to example file
Assuming your start of month and day numbers are stored as values, not text, then use this:
=IFERROR(VLOOKUP($A$1+F3-1,Table13!$A:$C,3,0),"")
Where Table13 is the worksheet where the lookup is happening with the data stored in columns A:C.
=IFERROR(VLOOKUP(VALUE($A$1)+VALUE(F3)-1,Table13!$A:$C,3,0),"")
Would work if the dates are text.

Excel Advanced Filtering Issues - Advice Needed

So basically I have a main table, and I want to filter that data to another table (normally easy) but I want this based upon 2 criteria. e.g. I want to filter the data of a specific department but only for the current month. The way I display the current month in the main table is by inserting the date from a userform and then by formatting that cell to just display the month. However, when using advanced filter I use the column headings that I want to filter e.g. department: mens, month: november (worked out using =now() then formatting to just display the month) but when I'm running the filter it's not picking out the information at all.
I think this lies with the way the month is worked out and displayed but I can't figure out another way to do this. Any help is greatly appreciated.
I'm also open to trying a new method of just selecting data for the current month if anyone has a cleaner way, as I'm sure there is one.
You have to use a formula in your criteria to specify what month you want to extract. But it's not terribly intuitive. Take a look at this sample. My starting list is the range A1:B7. My criteria is in range D1:E2. The Department is straightforward; I just entered "3". (Obviously, without the quotes.) But instead of a Month criteria, I added "GetMonth" and entered the formula shown in the formula bar. You can name this whatever you want, but it can't be the same as one of the headers in your source list. (Yeah, I checked.) The formula checks to see if the current month of the date in cell B2 is 12, which is December, and returns TRUE or FALSE. You could use 11 for November. The advanced filter will apply the reference to cell B2 that's in the formula in a relative fashion to all cells in the Month column. And Viola! my output in range A10:B11 is what you'd expect it to be.

Resources