Option Explicit
'columns in Data sheet
Const colID As Long = 1
Const colStatus As Long = 2
Const colName As Long = 3
Const colJob As Long = 4
Const colHours As Long = 5
Const colOffice As Long = 6
Public Sub CheckNewRecordOpenTest()
Dim wsData As Worksheet
Dim wsOpen As Worksheet, wsClosed As Worksheet, wsFilled As Worksheet
Dim n As Long, iData As Long, iNew As Long
Dim intsh2Row As Integer
Set wsData = Worksheets("Raw Data")
Set wsOpen = Worksheets("Open")
Set wsClosed = Worksheets("Closed")
Set wsFilled = Worksheets("Filled")
With wsData
For iData = 2 To .Cells(1, 1).CurrentRegion.Rows.Count
Select Case LCase(.Cells(iData, colStatus).Value)
' 1 2 3 4 5 6
'Name Job Description Hours Office ID Number Status
Case "open"
n = 0
On Error Resume Next
n = Application.WorksheetFunction.Match(.Cells(iData, colID).Value, wsOpen.Columns(5), 0)
On Error GoTo 0
If n = 0 Then ' new one so add to end
iNew = wsOpen.Cells(wsOpen.Rows.Count, 5).End(xlUp).Row + 1
wsOpen.Cells(iNew, 1).Value = .Cells(iData, colName).Value
wsOpen.Cells(iNew, 2).Value = .Cells(iData, colJob).Value
wsOpen.Cells(iNew, 3).Value = .Cells(iData, colHours).Value
wsOpen.Cells(iNew, 4).Value = .Cells(iData, colOffice).Value
wsOpen.Cells(iNew, 5).Value = .Cells(iData, colID).Value
wsOpen.Cells(iNew, 6).Value = "Open"
End If
' 1 2 3 4 5 6
'Status Name Job Description Hours Office ID Number
Case "closed"
n = 0
On Error Resume Next
n = Application.WorksheetFunction.Match(.Cells(iData, colID).Value, wsClosed.Columns(6), 0)
On Error GoTo 0
If n = 0 Then ' new one so add to end
iNew = wsClosed.Cells(wsClosed.Rows.Count, 5).End(xlUp).Row + 1
wsClosed.Cells(iNew, 1).Value = "Closed"
wsClosed.Cells(iNew, 2).Value = .Cells(iData, colName).Value
wsClosed.Cells(iNew, 3).Value = .Cells(iData, colJob).Value
wsClosed.Cells(iNew, 4).Value = .Cells(iData, colHours).Value
wsClosed.Cells(iNew, 5).Value = .Cells(iData, colOffice).Value
wsClosed.Cells(iNew, 6).Value = .Cells(iData, colID).Value
End If
' 1 2 3 4 5 6
'Job Description ID Number Status Name Hours Office
Case "filled"
n = 0
On Error Resume Next
n = Application.WorksheetFunction.Match(.Cells(iData, colID).Value, wsFilled.Columns(2), 0)
On Error GoTo 0
If n = 0 Then ' new one so add to end
iNew = wsFilled.Cells(wsFilled.Rows.Count, 5).End(xlUp).Row + 1
wsFilled.Cells(iNew, 1).Value = .Cells(iData, colJob).Value
wsFilled.Cells(iNew, 2).Value = .Cells(iData, colID).Value
wsFilled.Cells(iNew, 3).Value = "Filled"
wsFilled.Cells(iNew, 4).Value = .Cells(iData, colName).Value
wsFilled.Cells(iNew, 5).Value = .Cells(iData, colHours).Value
wsFilled.Cells(iNew, 6).Value = .Cells(iData, colOffice).Value
End If
End Select
Next iData
End With
End Sub