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

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

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,118,812
Messages
5,574,458
Members
412,595
Latest member
slim313
Top