Days of the month problem

chead5

Active Member
Joined
Jun 7, 2004
Messages
356
I have a dialog box that asks the user for a month (listbox, string variable) and year (another listbox, string variable).

Here is what I need to do:
I need to take the user input, and somehow loop through each day of just that month.

here is the code i have:

Code:
Sub create_folders()
Dim my_book As Workbook
Dim my_sheet As Worksheet
Dim i As Integer
Dim fs As Object
Dim test As Boolean
Dim year_path As String
Dim start_date As Date
Dim end_date As Date

Set fs = CreateObject("Scripting.FileSystemObject")
Set my_book = ThisWorkbook

'launch dialog box
frm_select.Show

If Module1.bln_cancel = True Then
    GoTo Bye
End If

year_path = "N:\Reports_" & Module1.my_year + "\"

If fs.folderexists("n:\Reports_" & Module1.my_year) = False Then
    MsgBox """N:\Reports_" & Module1.my_year + """ does not exist." & Chr(13) + "Please create it try again.", vbOKOnly, "Error"
    GoTo Bye
End If

start_date = Module1.my_month + "/" + Module1.my_year

I can't get the end_date part. I need to set it to the last day of the month.


Any help?
 

Some videos you may like

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Example:

Code:
Sub Test()
    Dim Mth As Integer
    Dim Yr As Integer
    Dim start_date As Date
    Dim end_date As Date
    Mth = 12
    Yr = 2005
    start_date = DateSerial(Yr, Mth, 1)
    end_date = DateSerial(Yr, Mth + 1, 0)
    MsgBox start_date & vbCrLf & end_date
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,530
Messages
5,596,699
Members
414,088
Latest member
rodriboraun

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
Top