VBA - Problem with Selecting Save As Directory

vba_monkey

Board Regular
Joined
Dec 18, 2013
Messages
112
Hello,

This code code comes at the end of a macro and is supposed to save the workbook in the correct folder. cmbEndMonth is selected by the user in a userform and the workbook should be saved in the corresponding Quarter folder for that year. The codes works but it always saves the workbook in the Q1 folder no matter which cmbEndMonth is selected.

Can anyone see what's wrong?

Code:
If cmbEndMonth = "1" Or "2" Or "3" Then
            Quarter = "Q1"
        ElseIf cmbEndMonth = "4" Or "5" Or "6" Then
            Quarter = "Q2"
        ElseIf cmbEndMonth = "7" Or "8" Or "9" Then
            Quarter = "Q3"
        Else
            Quarter = "Q4"
    End If
        
    Filepath = "R:\SJE Shared\DMU\Data Checking\" & Year(Date) & "\" & Quarter & "\Gross Premium\"
    ActiveWorkbook.SaveAs Filename:=Filepath & Replace(ActiveWorkbook.Name, "ver_3.0_LIVE.xlsm", Format(Date, "mm") & "_" & Format(Date, "dd") & ".xlsx"), FileFormat:=51, AccessMode:=xlShared

Thanks
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try:

Code:
Select Case CLng(cmbEndMonth)
    Case 1, 2, 3
        Quarter = "Q1"
    Case 4, 5, 6
        Quarter = "Q2"
    Case 7, 8, 9
        Quarter = "Q3"
    Case Else
        Quarter = "Q4"
End Select
    
        
FilePath = "R:\SJE Shared\DMU\Data Checking\" & Year(Date) & "\" & Quarter & "\Gross Premium\"
ActiveWorkbook.SaveAs filename:=FilePath & Replace(ActiveWorkbook.Name, "ver_3.0_LIVE.xlsm", Format(Date, "mm") & "_" & Format(Date, "dd") & ".xlsx"), FileFormat:=51, AccessMode:=xlShared
 
Upvote 0
Thanks for the feedback - have a good day!
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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