Hi All, I'm an avid reader to this forum and you all have been a great help to me since I've started using VBA and macros more actively.
I'm still pretty amateur to this but I've been working with my Dad (whose got a pretty good handle on these kinds of things) to create an automated program that will take an excel sheet that has data records for every minute over a two week period in a excel sheet, separate the data into byDay periods, and save as a .csv file so that we can later use a stat program to read the data. The program utilizes both Access and Excel. Access is used to organize the data into tables by day and then each table is exported out to their own excel sheets and saved as a .csv file.
Now the problem is that when I look into the by day excel files, sometimes they are not sorted correctly, meaning instead of the record beginning at 0:01 (12:01 AM), a random chunk of data will be at the top of the sheet.
Here's what we wrote in the module regarding the the format of the excel sheet. We know it has to be something in excel, because we are able to check the access tables and see that they all are in the correct order.
If you are able to see what may be the problem, let me know and I will be very grateful for it. I've spent quite a long time on what seems to me to be a simple problem.
I'm still pretty amateur to this but I've been working with my Dad (whose got a pretty good handle on these kinds of things) to create an automated program that will take an excel sheet that has data records for every minute over a two week period in a excel sheet, separate the data into byDay periods, and save as a .csv file so that we can later use a stat program to read the data. The program utilizes both Access and Excel. Access is used to organize the data into tables by day and then each table is exported out to their own excel sheets and saved as a .csv file.
Now the problem is that when I look into the by day excel files, sometimes they are not sorted correctly, meaning instead of the record beginning at 0:01 (12:01 AM), a random chunk of data will be at the top of the sheet.
Here's what we wrote in the module regarding the the format of the excel sheet. We know it has to be something in excel, because we are able to check the access tables and see that they all are in the correct order.
Code:
'Make sure excel is visible on the screen
XlBook.Windows(1).Visible = True
'Define the sheet in the Workbook as XlSheet
Set XlSheet = XlBook.Worksheets(1)
'Insert Row and the Value in the Excel sheet starting at specified cell
XlSheet.Range("A1:D1440").Sort key1:=Range("A1:B1440"), order1:=xlAscending 'Sorts data (from cell A3 to last data entry in that column) in ascending order
Pause (3)
XlSheet.Rows(1).EntireRow.Insert
XlSheet.Range("A1") = "PLOT TITLE: " + CStr(DatePart("m", X)) + "." + CStr(DatePart("d", X)) + "." + CStr(DatePart("yyyy", X)) + "_" + cow
XlSheet.Rows(2).EntireRow.Insert
XlSheet.Range("A2") = "#"
XlSheet.Range("B2") = "Date Time, GMT-05:00"
XlSheet.Range("C2") = "Y Accel, g"
XlSheet.Range("D2") = "Z Accel, g"
Pause (5) 'Executes a 2 second delay. Excel automation is tempermental.
XlBook.Save
XlBook.Close True
'Status this day's record as "processed"
dqt.Edit
dqt!Processed = True
dqt!TableName = y
dqt!CSVLocation = filepath
dqt.Update
Else
MsgBox "There are no records left to process."
End If
PROC_EXIT:
Exit Sub
PROC_ERR:
Debug.Print Err.Description
Stop
Resume
End Sub
If you are able to see what may be the problem, let me know and I will be very grateful for it. I've spent quite a long time on what seems to me to be a simple problem.