Using Input Box to determine month

Needsomehelp10

New Member
Joined
Sep 5, 2017
Messages
18
Hey guys,

I am trying to use an input box to help determine a variable in my vba code. For example, I want an inbox to pop up and ask what month is it (1-12)? If they answer 1, then the month used for the code will be January and so on. Below is the code I have currently. Is what I want to do possible? The variable I want the input box answer to change is the mnth variable. Thanks in advance.



Subfilelocation ()

Dim Filename As String
Dim FilePath As String
Dim Yer As Integer
Dim mnth As String
mnth = "October "
Yer = 2017
If Range("A2") = "A" Then
Filename = ActiveSheet.Name & " TB - " & mnth & Yer
FilePath = "Insert File Path Here"
ActiveSheet.SaveAs Filename:=FilePath & "" & Filename, FileFormat:=51
ElseIf Range("A2") = "B" Then
Filename = ActiveSheet.Name & " TB - " & mnth & Yer
FilePath = "Insert Alternative File Path Here"
ActiveSheet.SaveAs Filename:=FilePath & "" & Filename, FileFormat:=51
End If
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Take a look at this block of code which will prompt for a month number and change to month name:
Code:
    Dim mnth As Byte
    mnth = InputBox("Enter month number")
    If (mnth >= 1) And (mnth <= 12) Then
        MsgBox Format(DateSerial(Year(Date), mnth, 1), "mmmm")
    Else
        MsgBox "You have not entered a valid month"
    End If
 
Upvote 0
Something like
Code:
Sub chk()
Dim ans As Long
Dim Mnth As String
ans = InputBox("Insert month number")
Mnth = MonthName(ans)
MsgBox Mnth
End Sub
 
Upvote 0
I never knew there was a MonthName function in VBA.
I like it!!!:)
 
Upvote 0
I actually thought it was an xl function, but when that didn't work, I hunted around & discovered that it's VBA instead.
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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