Hi everyone,
I am using the following code to download data from a folder which is filled with files on a regular basis.
The files are supplied from Tuesday to Saturday, so on Monday I need to point not to DataX_CM_FUT1_" & dYes & "_" & dTod & "_000501UTC.csv" but to DataX_CM_FUT1_" & dFriday & "_" & dSaturday & "_000501UTC.csv"
I could create a parameter to say if today is Monday, then do this, otherwise do that. But this type of logic is a floodgate once there is more than two options to consider. Appreciate any 'smarter' solutions that will facilitate shorter code. Thank you.
I am using the following code to download data from a folder which is filled with files on a regular basis.
The files are supplied from Tuesday to Saturday, so on Monday I need to point not to DataX_CM_FUT1_" & dYes & "_" & dTod & "_000501UTC.csv" but to DataX_CM_FUT1_" & dFriday & "_" & dSaturday & "_000501UTC.csv"
I could create a parameter to say if today is Monday, then do this, otherwise do that. But this type of logic is a floodgate once there is more than two options to consider. Appreciate any 'smarter' solutions that will facilitate shorter code. Thank you.
VBA Code:
Sub copyColDataOld()
Dim lastRow As Long
Dim myApp As Excel.Application
Dim wkBk As Workbook
Dim wkSht As Object
Dim dTod As String, dYes As String
dTod = Format(Date, "yyyy-mm-dd")
dYes = Format(Date - 1, "yyyy-mm-dd")
Set myApp = CreateObject("Excel.Application")
Set wkBk = myApp.Workbooks.Open("Dump\DataX_CM_FUT1_" & dYes & "_" & dTod & "_000501UTC.csv")
lastRow = wkBk.Sheets(1).Range("A" & Rows.Count).End(xlUp).Row
wkBk.Sheets(1).Range("C2:H" & lastRow).Copy
myApp.DisplayAlerts = False
wkBk.Close
myApp.Quit
Set wkBk = Nothing
Set myApp = Nothing
Set wkBk = ActiveWorkbook
Set wkSht = wkBk.Sheets("NewData")
wkSht.Activate
Range("A1").Select
wkSht.Paste
End Sub