Using a variable in a formula

ingasos

New Member
Joined
Oct 3, 2019
Messages
7
I've seen a similar question to the append with the heading of "Using a variable in a formula", but I can't fine the correct syntax for my particular problem which is as follows:

=DATE(YEAR(summary_start_date)+1,MONTH(summary_start_date),DAY(summary_start_date))


I want to change the + part where it says +1 to a variable called year_asc_dec which could either be a + or a - so I would end up with +1 or -1 in the above formula.

Any thoughts or suggestions. Basically a want to produce a date table which is either descending or ascending from a given start date.


Thanks in advance for any thoughts
Siggi
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
I want to change the + part where it says +1 to a variable called year_asc_dec which could either be a + or a - so I would end up with +1 or -1 in the above formula.

Hi, you could try like this:

=DATE(YEAR(summary_start_date)+(year_asc_dec&1),MONTH(summary_start_date),DAY(summary_start_date))
 
Upvote 0
Hi & welcome to MrExcel.
How about
=DATE(YEAR(summary_start_date)+year_asc_dec,MONTH(summary_start_date),DAY(summary_start_date))
 
Upvote 0
Welcome to the Board!

Variables are found in VBA. Excel formulas may used "named ranges", but not really variables.
So, where are you talking about doing this, in VBA or in an Excel formula on the sheet?

If "year_asc_dec" is a named range of a single cell holding a number, then you just update your formula to work like the other parts of it, i.e.
Code:
[COLOR=#1D2129][FONT=Helvetica]=DATE(YEAR(summary_start_date)[/FONT][/COLOR][B]+[COLOR=#ff0000]year_asc_dec[/COLOR],[/B][B]MONTH(summary_start_date),DAY(summary_start_date))[/B]
 
Upvote 0
Hi, you could try like this:

=DATE(YEAR(summary_start_date)+(year_asc_dec&1),MONTH(summary_start_date),DAY(summary_start_date))

WOW - that works!!!!! I had been close to the solution, but I missed out the + at the start of this section +(year_asc_dec&1)

Many Many thanks

Siggi
 
Upvote 0
Thanks Joe4 unfortunately your suggestion did not work for me, but as you can see someone came back with the working solution

Thanks again for looking at my problem
Siggi
 
Upvote 0
Hi & welcome to MrExcel.
How about
=DATE(YEAR(summary_start_date)+year_asc_dec,MONTH(summary_start_date),DAY(summary_start_date))

Thanks Fluff for having a look at my problem / challenge!!Fluff. Unfortunately it did not work but again it was close. This one worked a treat

=DATE(YEAR(summary_start_date)+(year_asc_dec&1),MONTH(summary_start_date),DAY(summary_start_date))
 
Upvote 0
Glad you got a solution & thanks for the feedback
 
Upvote 0
Thanks everyone who helped out and coming back with suggestions. It's great to see that this discussion group people people out like myself.

Hopefully I can help someone out in the future.

Siggi
 
Upvote 0
Sorry, I misunderstood/misread the question!
Glad you got an answer that works.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

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.
Go back
Back
Top