Issues with excess months in a 9 months period

USA_kker

New Member
Joined
Oct 17, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I'm struggling with this table generating an additional month 4-9 for 2022 in October
Visible.png


Please have a look at my code, as I fail to see the issue here.



Dim Months, Years, Monthss, Yearss, Monthsss, Yearsss As String

'Find next month from today with 2 digit month number
If Month(Now) = 12 Then
Months = "01"
Years = Year(Now) + 1
ElseIf Month(Now) < 9 Then
Months = "0" & (Month(Now) + 1)
Years = Year(Now)
Else
Months = Month(Now) + 1
Years = Year(Now)
End If

'Find month an year for +1, +3 and +6 months
If Months = "12" Then
Monthss = "02"
Yearss = Years + 1
Monthsss = "05"
Yearsss = Years + 1
ElseIf Months = "11" Then
Monthss = "01"
Yearss = Years + 1
Monthsss = "04"
Yearsss = Years + 1
ElseIf Months = "10" Then
Monthss = "12"
Yearss = Years
Monthsss = "03"
Yearsss = Years + 1
ElseIf Months = "09" Then
Monthss = "11"
Yearss = Years
Monthsss = "02"
Yearsss = Years + 1
ElseIf Months = "08" Then
Monthss = "10"
Yearss = Years
Monthsss = "01"
Yearsss = Years + 1
ElseIf Months = "07" Then
Monthss = "09"
Yearss = Years
Monthsss = "12"
Yearsss = Years
ElseIf Months = "06" Then
Monthss = "08"
Yearss = Years
Monthsss = "11"
Yearsss = Years
ElseIf Months = "05" Then
Monthss = "07"
Yearss = Years
Monthsss = "10"
Yearsss = Years
ElseIf Months = "04" Then
Monthss = "06"
Yearss = Years
Monthsss = "09"
Yearsss = Years
ElseIf Months = "03" Then
Monthss = "05"
Yearss = Years
Monthsss = "08"
Yearsss = Years
ElseIf Months = "02" Then
Monthss = "04"
Yearss = Years
Monthsss = "07"
Yearsss = Years
ElseIf Months = "01" Then
Monthss = "03"
Yearss = Years
Monthsss = "06"
Yearsss = Years
End If
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Why not using DateAdd, to get real date from Now +1,3,6 months first, then get month and year later?
VBA Code:
Option Explicit
Sub test()
Dim Months, Years, Monthss, Yearss, Monthsss, Yearsss As String
Months = Month(DateAdd("m", 1, Now)) ' plus 1 month
Years = Year(DateAdd("m", 1, Now)) ' plus 1 month
Monthss = Month(DateAdd("m", 3, Now)) ' plus 3 months
Yearss = Year(DateAdd("m", 3, Now)) ' plus 3 months
Monthsss = Month(DateAdd("m", 6, Now)) ' plus 6 months
Yearsss = Year(DateAdd("m", 6, Now)) ' plus 6 months
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,428
Members
448,961
Latest member
nzskater

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