Date setting according to year and month selection

acemi

New Member
Joined
Mar 14, 2024
Messages
1
Office Version
  1. 2021
  2. 2019
  3. 2016
Platform
  1. Windows
Hello,
I am a new member of your site. I would like to thank everyone who shares in this forum. I would like to ask my first question with your permission.
Inside the Private Sub Worksheet_Change(ByVal Target As Range) procedure
Year in Cell D2 (drop down list and variable like 2021, 2022, 2023, 2024, ...))
Month in Cell D3 (drop down list and variable like January, February, March...)
According to the selected Year and Month
If the year is 2024 and the month is January
15th of December of the previous year (as 15.12.2023) in Cell F2
The 14th of the year and month selected in cell F3 (as 14.01.2024)
If the year is 2024 and the month is December
The 15th of the year and month selected in Cell F2 (as 15.12.2024)
In cell F3, enter the 14th of January of the month one year later (as 14.01.2025)
In other years and months
15th of the previous Month in Cell F2
I need a macro code that I can transfer the 14th of the next month to the F3 cell. I would be pleased if you can help
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hello and welcome to MrExcel forum, @acemi!
if I've understood the goal correctly:
VBA Code:
Range("F3").Value = DateSerial(Range("D2").Value, Range("D3").Value + 1, Range("F2").Value - 1)
 
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