lopiteaux
Board Regular
- Joined
- Jun 8, 2011
- Messages
- 77
Hi all - I've got a little problem with a macro I'm running which is quite frankly, got me completely dumstruck.
In short, the macro has two parts - firstly, it imports data from a source .txt file and copies it into the controlfile (the file containing the macro). So far, so good. Because the import uses a VLOOKUP to find a date corresponding to the previous business day, I've used the following code:
Dim RateDate as Date
strName = InputBox("Input Report Date", "Import Report", Format(Now, "ddmmyy"))
specyear = Right(strName, 2)
specmonth = Left(Right(strName, 4), 2)
specday = Left(strName, 2)
If Weekday(Date) = 2 Then
RateDate = Format((specday - 3 & "/" & specmonth & "/" & "20" & specyear), "dd/mm/yyyy")
Else
RateDate = Format((specday - 1 & "/" & specmonth & "/" & "20" & specyear), "dd/mm/yyyy")
End If
As you can see it uses an InpotBox with today as the default date and then manipulates this date into the correct format for my VLOOKUP. It then executes the following bit of code to look up the value:
USDRate = Application.VLookup(CLng(RateDate), Columns("A:C"), 2, False)
Windows(ControlFile).Activate
Sheets("IDRRates").Activate
Range("C2").Select
ActiveCell.Value = USDRate
and subsequently copies it into the controlfile. As mentioned, up until this point it all works fine. The next step in the macro - the step giving me the headache - copies the information off the controlfile into a .csv file, which is then uploaded via XML into another piece of software. The software recognises dates in the British format, i.e. dd/mm/yyyy, and in the controlfile the dates are saved and displayed as such (if I reformat the dates to d mmmm yyyy I get the correct date), but for some or other reason just copying it over doesn't seem to work - the software rejects the import, quoting the value of the date as incorrect (in this example, quoting it as "6/7/2011" when the date displayed in the .xls controlfile is "07/06/2011").
I used the following bit of code on the dates to transform them into date from text - which incidentally, worked perfectly for a good two weeks before breaking on me:
Range("B2").Select 'Where B2 is the start of the series.
Do
ActiveCell.Value = Left(ActiveCell, 10)
ActiveCell.Offset(1, 0).Select
Loop Until IsEmpty(ActiveCell.Value)
Range("B:B").Select
Selection.NumberFormat = "dd/mm/yyyy"
If I run this code in step through mode, I can see that the dates are effectively flipped around - i.e. from British "07/06/2011" to American "06/07/2011", causing issues with the system.
Can someone please help? I've been banging my head against the wall on this for a day or two and cannot seem to find the answer...
Thanks,
C.
In short, the macro has two parts - firstly, it imports data from a source .txt file and copies it into the controlfile (the file containing the macro). So far, so good. Because the import uses a VLOOKUP to find a date corresponding to the previous business day, I've used the following code:
Dim RateDate as Date
strName = InputBox("Input Report Date", "Import Report", Format(Now, "ddmmyy"))
specyear = Right(strName, 2)
specmonth = Left(Right(strName, 4), 2)
specday = Left(strName, 2)
If Weekday(Date) = 2 Then
RateDate = Format((specday - 3 & "/" & specmonth & "/" & "20" & specyear), "dd/mm/yyyy")
Else
RateDate = Format((specday - 1 & "/" & specmonth & "/" & "20" & specyear), "dd/mm/yyyy")
End If
As you can see it uses an InpotBox with today as the default date and then manipulates this date into the correct format for my VLOOKUP. It then executes the following bit of code to look up the value:
USDRate = Application.VLookup(CLng(RateDate), Columns("A:C"), 2, False)
Windows(ControlFile).Activate
Sheets("IDRRates").Activate
Range("C2").Select
ActiveCell.Value = USDRate
and subsequently copies it into the controlfile. As mentioned, up until this point it all works fine. The next step in the macro - the step giving me the headache - copies the information off the controlfile into a .csv file, which is then uploaded via XML into another piece of software. The software recognises dates in the British format, i.e. dd/mm/yyyy, and in the controlfile the dates are saved and displayed as such (if I reformat the dates to d mmmm yyyy I get the correct date), but for some or other reason just copying it over doesn't seem to work - the software rejects the import, quoting the value of the date as incorrect (in this example, quoting it as "6/7/2011" when the date displayed in the .xls controlfile is "07/06/2011").
I used the following bit of code on the dates to transform them into date from text - which incidentally, worked perfectly for a good two weeks before breaking on me:
Range("B2").Select 'Where B2 is the start of the series.
Do
ActiveCell.Value = Left(ActiveCell, 10)
ActiveCell.Offset(1, 0).Select
Loop Until IsEmpty(ActiveCell.Value)
Range("B:B").Select
Selection.NumberFormat = "dd/mm/yyyy"
If I run this code in step through mode, I can see that the dates are effectively flipped around - i.e. from British "07/06/2011" to American "06/07/2011", causing issues with the system.
Can someone please help? I've been banging my head against the wall on this for a day or two and cannot seem to find the answer...
Thanks,
C.