Hi all:
Here is my problem with vba code using Excel 2003. I get data in text file (text file has date as first column in following format:
31/12/2015 4:00:00 PM,120.45,120.7,120.42,120.62. Current date is at end of file.
Then I import this data into Excel to plot charts. Date in excel is shown as format: 21-Sep-15 (however underlying it is: 21/09/2015 10:00:00 AM).
What I want in excel, in last data row, date cell, check last date/current date min and sec portion with following condition:
if sec = 00 and min = 15 or 30 or 45 or 00 then
do nothing
else
select last line of data and delete entire lines data.
I did write some code, it gives me error 13, type mismatch. Any help would be appreciated. Attached is my code:
__________________________________________________________________
Here is my problem with vba code using Excel 2003. I get data in text file (text file has date as first column in following format:
31/12/2015 4:00:00 PM,120.45,120.7,120.42,120.62. Current date is at end of file.
Then I import this data into Excel to plot charts. Date in excel is shown as format: 21-Sep-15 (however underlying it is: 21/09/2015 10:00:00 AM).
What I want in excel, in last data row, date cell, check last date/current date min and sec portion with following condition:
if sec = 00 and min = 15 or 30 or 45 or 00 then
do nothing
else
select last line of data and delete entire lines data.
I did write some code, it gives me error 13, type mismatch. Any help would be appreciated. Attached is my code:
Code:
Sub CheckLastDataRowIntraDay()
'For Intra-day, check Min & Sec in Date column,
'if Sec = 00 and Min = cell value e.g. 15 or 30 or 45 or 0, then do nothing. Else select last line and delete entire line.
Dim TestValue As Integer, LR As Integer, myDate As String
LR = Range("CA" & Rows.Count).End(xlUp).Row
Range("CA1").Value = LR
Range("CA" & LR).Select
Selection.NumberFormat = "mm/dd/yyyy hh:mm:ss"
TestValue = Range("AG55").Value
myDate = Range("CA" & LR).Value
'myDate = Range("CA" & Rows.Count).End(xlUp).Value
If Mid(myDate, 18, 2) = "00" And _
(Abs(Mid(myDate, 15, 2)) Mod (TestValue) = 0) Then
'do nothing
Else
ActiveSheet.Range("CA" & LR & ":CM" & LR).Select
Selection.ClearContents
End If
End Sub
Mod edit : post moved to proper forum …