previous month

SAM1961

New Member
Joined
Sep 11, 2024
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
Hi. I am facing a problem. I want month name not the current month but any month to change in previous month name in excel VBA.
I have a form where user fills the month name. This month name I want to change in previous month i.e; subtract one to get the previous month.
thanks
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Something like this (Am no VBA expert)

With Month name in A1...

Code:
Sub k1()
var1 = Left(Range("A1"), 3)
var2 = InStr("JanFebMarAprMayJunJulAugSepOctNovDec", var1)
If var2 = 1 Then var3 = 12 Else var3 = ((var2 - 1) / 3) Mod 12
var4 = MonthName(var3)
MsgBox var4
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,175
Members
452,615
Latest member
bogeys2birdies

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