Hello
Below code is using the find method to search through a list and when an error occurs (find does not locate) it will copy over the missing information from one workbook to another. My issue is the first time the function does not find the value in the list it is not going to the error handling section (result is empty).
Set ws_shipments = Workbooks("RailShipments2013_14.xlsm").Worksheets("Database")
Set ws = Workbooks("AberdeenShipments13.xlsm").Worksheets("Tables")
Set station_range = ws.Columns("Y")
Set result = ws.Range("Y1")
lastspec = ws_shipments.Cells(ws_shipments.Rows.Count, "B").End(xlUp).Row
For row_count = 36000 To lastspec
lookfor = ws_shipments.Cells(row_count, "B").Value
On Error GoTo add_spec
Set result = station_range.Find(lookfor, result, LookIn:=xlValues, lookat:=xlPart, searchorder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
Next row_count
Exit Sub
add_spec:
lastcell = ws.Cells(ws.Rows.Count, "Y").End(xlUp).Row
addnew = lastcell + 1
'copy information from ws_shipments to ws
The data is very long so I have it starting at line 36000, the first value which should reqult in the error is at line 36951. Code is working as expected for all rows which should be copied over following line 36951.
What am I missing?
Below code is using the find method to search through a list and when an error occurs (find does not locate) it will copy over the missing information from one workbook to another. My issue is the first time the function does not find the value in the list it is not going to the error handling section (result is empty).
Set ws_shipments = Workbooks("RailShipments2013_14.xlsm").Worksheets("Database")
Set ws = Workbooks("AberdeenShipments13.xlsm").Worksheets("Tables")
Set station_range = ws.Columns("Y")
Set result = ws.Range("Y1")
lastspec = ws_shipments.Cells(ws_shipments.Rows.Count, "B").End(xlUp).Row
For row_count = 36000 To lastspec
lookfor = ws_shipments.Cells(row_count, "B").Value
On Error GoTo add_spec
Set result = station_range.Find(lookfor, result, LookIn:=xlValues, lookat:=xlPart, searchorder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
Next row_count
Exit Sub
add_spec:
lastcell = ws.Cells(ws.Rows.Count, "Y").End(xlUp).Row
addnew = lastcell + 1
'copy information from ws_shipments to ws
The data is very long so I have it starting at line 36000, the first value which should reqult in the error is at line 36951. Code is working as expected for all rows which should be copied over following line 36951.
What am I missing?