Hi guys,
I have a query about a section in a macro im trying to create.
I have two workbooks:
1) DataDump.xls
2) CurrentRecords.xls
The DataDumb file is populated automatically every at every 32mins past the hour via a seperate DB. A macro within the CurrentRecords.xls copies some of the records within the DataDump.xls every 35mins - in the attempt to capture the most up-to-date info.
What i am trying to do is that, before CurrentRecords.xls copies the records within DataDump.xls, i would like it to check to see if a value in Column A (ID number) within the CurrentRecords exists within Column A (ID number) in the DataDump. If yes, carry on the macro as usual. If no, copy that entire row from CurrentRecords to sheet2 in the CurrentRecords.xls.
Here is what i have so far:
I have a query about a section in a macro im trying to create.
I have two workbooks:
1) DataDump.xls
2) CurrentRecords.xls
The DataDumb file is populated automatically every at every 32mins past the hour via a seperate DB. A macro within the CurrentRecords.xls copies some of the records within the DataDump.xls every 35mins - in the attempt to capture the most up-to-date info.
What i am trying to do is that, before CurrentRecords.xls copies the records within DataDump.xls, i would like it to check to see if a value in Column A (ID number) within the CurrentRecords exists within Column A (ID number) in the DataDump. If yes, carry on the macro as usual. If no, copy that entire row from CurrentRecords to sheet2 in the CurrentRecords.xls.
Here is what i have so far:
Code:
Public dTime As Date
Sub Collect_RawData()
'' Update the data every 20 seconds
dTime = Now + TimeValue("00:35:00")
Application.OnTime dTime, "Collect_RawData"
'' Local Variables \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Dim wkbData As Workbook
Dim cell As Range
Dim c1, c2, r1, r2 As Integer
'' Retreive all available data in source workbook \\\\\\\\\\\\\\\\\\\\\\\\\
'' Open DawData \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Set wkbData = Workbooks.Open(Filename:="C:\Documents and Settings\lewisH\Desktop\DataDump.xls", ReadOnly:=False)
'' Check if A1 in RawData is not blank \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
If wkbData.Worksheets("Sheet1").Range("A1") = "" Then
wkbData.Close False
Else
r1 = 1
'' Start on second row to stop writing in headings \\\\\\\\\\\\\\\\\\\\
r2 = 2
Do Until r1 = Application.WorksheetFunction.CountA(wkbData.Worksheets("Sheet1").Columns(1)) + 1
'' If the values in RawData Coloumn 1 aren't blank, then \\\\\\\\\\\\\\
If wkbData.Worksheets("Sheet1").Cells(r1, 1).Value <> "" Then
'' Copy row from RawData sheet to Comms sheet \\\\\\\\\\\\\\\\\\\\\\\\\
ThisWorkbook.Sheets("Sheet1").Cells(r2, 1).Value = wkbData.Worksheets("Sheet1").Cells(r1, 1).Value
ThisWorkbook.Sheets("Sheet1").Cells(r2, 2).Value = wkbData.Worksheets("Sheet1").Cells(r1, 2).Value
ThisWorkbook.Sheets("Sheet1").Cells(r2, 3).Value = wkbData.Worksheets("Sheet1").Cells(r1, 3).Value
ThisWorkbook.Sheets("Sheet1").Cells(r2, 4).Value = wkbData.Worksheets("Sheet1").Cells(r1, 4).Value
ThisWorkbook.Sheets("Sheet1").Cells(r2, 5).Value = wkbData.Worksheets("Sheet1").Cells(r1, 5).Value
ThisWorkbook.Sheets("Sheet1").Cells(r2, 6).Value = wkbData.Worksheets("Sheet1").Cells(r1, 6).Value
ThisWorkbook.Sheets("Sheet1").Cells(r2, 7).Formula = "=IF((F" & r2 & ")="""", """", NETWORKDAYS((F" & r2 & "),NOW())-1)"
ThisWorkbook.Sheets("Sheet1").Cells(r2, 8).Formula = "=$F" & r2 & "+(INDEX(CommsFrequency!$B$3:$D$7,MATCH(Sheet1!$B" & r2 & ",CommsFrequency!$B:$B,0)-2,3)*0.000694444444444444)"
'' Populate next row
r2 = r2 + 1
End If
' ////////////////////////////////////////////////////////////////////////
' To see if ID number within CurrentRecords exists within DataDump
' If Application.WorksheetFunction.CountIf(ThisWorkbook.Sheets("Sheet1").Column(1), wkbData.Sheets("Sheet1").cell(r1, 1).Value) > 0 Then
' Move entire missing row from CurrentRecords Sheet1 to CurrentRecords Sheet2
' End If
' ////////////////////////////////////////////////////////////////////////
r1 = r1 + 1
Loop
wkbData.Close False
End If
'' Loop
'' Save and close the Comms file \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
ActiveWorkbook.Saved = True
' ActiveWorkbook.Close SaveChanges:=True
End Sub