I have a macro that transfer data from other worksheet into a final worksheet and it’s condition is base on the filename with dates (example “myfile-2005-10-31.xls”), now the problem arises on “myfile-2005-11-01.xls” which is the Nov 1st, I have to rename the file to “myfile-2005-10-32.xls” which we don’t have Oct 32nd in order to continue picking data from the source files. This macro don't pick Nov 1. Do you have any suggestion on how to deal with dates especially for tomorrows date Nov. 1. Please !!!
Public MyLine
Sub NewDailyReports()
' by omypet
Mysheet = ActiveSheet.Name
mypath = ActiveWorkbook.Path
If Mysheet = "2005" Then
MyLine = ActiveCell.Row
FrmLine.TxtLine.Text = MyLine
FrmLine.Show
Mysheet = ActiveSheet.Name
Mydate = Range("A" & MyLine)
MycellA = "A" & MyLine
MycellB = "B" & MyLine
MycellC = "C" & MyLine
Do While Mydate < Date Or Mydate = Date And Mydate <> ""
MyDay = Day(Range("A" & MyLine)) + 1
If Len(MyDay) = 1 Then
MyDay = "0" & MyDay + 1
End If
MyMonth = Month(Range("A" & MyLine))
If Len(MyMonth) = 1 Then
MyMonth = "0" & MyMonth
End If
MyYear = Right(Year(Range("A" & MyLine)), 4)
MyDateFile1 = "myfile-" & MyYear & "-" & MyMonth & "-" & MyDay & ".xls"
If Dir(mypath & "\" & MyDateFile1) = "" Then
If Range(MycellB).Value = "" Then
Range(MycellB).Value = ""
End If
If Range(MycellC).Value = "" Then
Range(MycellC).Value = ""
End If
If Range(MycellD).Value = "" Then
Range(MycellD).Value = ""
End If
Else
FormulaB = "='" & mypath & "\[" & MyDateFile1 & "]Summary'!$K$13"
Range(MycellB).Formula = FormulaB
FormulaC = "='" & mypath & "\[" & MyDateFile1 & "]Summary'!$E$22"
Range(MycellC).Formula = FormulaC
FormulaD = "='" & mypath & "\[" & MyDateFile1 & "]Summary'!$E$23"
Range(MycellD).Formula = FormulaD
FormulaE = "='" & mypath & "\[" & MyDateFile1 & "]Production'!$M$9"
End If
MyLine = MyLine + 1
Mydate = Range("A" & MyLine)
MycellA = "A" & MyLine
MycellB = "B" & MyLine
MycellC = "C" & MyLine
MycellD = "D" & MyLine
Loop
End If
End Sub
Public MyLine
Sub NewDailyReports()
' by omypet
Mysheet = ActiveSheet.Name
mypath = ActiveWorkbook.Path
If Mysheet = "2005" Then
MyLine = ActiveCell.Row
FrmLine.TxtLine.Text = MyLine
FrmLine.Show
Mysheet = ActiveSheet.Name
Mydate = Range("A" & MyLine)
MycellA = "A" & MyLine
MycellB = "B" & MyLine
MycellC = "C" & MyLine
Do While Mydate < Date Or Mydate = Date And Mydate <> ""
MyDay = Day(Range("A" & MyLine)) + 1
If Len(MyDay) = 1 Then
MyDay = "0" & MyDay + 1
End If
MyMonth = Month(Range("A" & MyLine))
If Len(MyMonth) = 1 Then
MyMonth = "0" & MyMonth
End If
MyYear = Right(Year(Range("A" & MyLine)), 4)
MyDateFile1 = "myfile-" & MyYear & "-" & MyMonth & "-" & MyDay & ".xls"
If Dir(mypath & "\" & MyDateFile1) = "" Then
If Range(MycellB).Value = "" Then
Range(MycellB).Value = ""
End If
If Range(MycellC).Value = "" Then
Range(MycellC).Value = ""
End If
If Range(MycellD).Value = "" Then
Range(MycellD).Value = ""
End If
Else
FormulaB = "='" & mypath & "\[" & MyDateFile1 & "]Summary'!$K$13"
Range(MycellB).Formula = FormulaB
FormulaC = "='" & mypath & "\[" & MyDateFile1 & "]Summary'!$E$22"
Range(MycellC).Formula = FormulaC
FormulaD = "='" & mypath & "\[" & MyDateFile1 & "]Summary'!$E$23"
Range(MycellD).Formula = FormulaD
FormulaE = "='" & mypath & "\[" & MyDateFile1 & "]Production'!$M$9"
End If
MyLine = MyLine + 1
Mydate = Range("A" & MyLine)
MycellA = "A" & MyLine
MycellB = "B" & MyLine
MycellC = "C" & MyLine
MycellD = "D" & MyLine
Loop
End If
End Sub