Sub Match_Copy_out_of_list()
Dim xlWsTrgt As Worksheet
Dim xlRng As Range
Dim i As Integer
Application.ScreenUpdating = False
Set xlWsTrgt = Worksheets("Import_file")
With ActiveWorkbook.Worksheets("Master Inst List")
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=.Cells(14, 2), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.Sort.SetRange .Range(.Cells(13, 2), .Cells(.Cells(.Rows.Count, 2).End(xlUp).Row, .Cells(11, .Columns.Count).End(xlToLeft).Column))
With .Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
For i = 14 To .Cells(.Rows.Count, 2).End(xlUp).Row
Set xlRng = xlWsTrgt.Columns(2).Find(What:=.Cells(i, 2).Value, LookIn:=xlFormulas, LookAt:=xlWhole)
If Not xlRng Is Nothing Then
xlWsTrgt.Range(xlWsTrgt.Cells(xlRng.Row, 3), xlWsTrgt.Cells(xlRng.Row, 26)).Value = Array( _
.Cells(i, 3).Value, .Cells(i, 4).Value, .Cells(i, 5).Value, .Cells(i, 6).Value, _
.Cells(i, 7).Value, "=IF(RC[-1]=0,RC[2]&""-""&RC[1]&RC[3]&RC[4]&RC[5],RC[-1])", _
.Cells(i, 9).Value, .Cells(i, 10).Value, .Cells(i, 11).Value, .Cells(i, 12).Value, _
.Cells(i, 13).Value, .Cells(i, 14).Value, .Cells(i, 15).Value, .Cells(i, 16).Value, _
.Cells(i, 17).Value, .Cells(i, 18).Value, .Cells(i, 19).Value, .Cells(i, 20).Value, _
.Cells(i, 21).Value, .Cells(i, 22).Value, .Cells(i, 23).Value, .Cells(i, 24).Value, _
.Cells(i, 25).Value, .Cells(i, 26).Value)
End If
Next i
End With
xlWsTrgt.Activate
With xlWsTrgt.Parent
.SaveAs _
Filename:="\\STORAGE\Project\2012\12334-5010-01-0358 - FAM - Suncor Fort Hills Crushing, Surge Facility & Conveyors\30 Design\Lists\Instrument List\list support Files\Import_file.txt", _
FileFormat:=xlText, _
CreateBackup:=False
.SaveAs _
Filename:="\\STORAGE\Project\2012\12334-5010-01-0358 - FAM - Suncor Fort Hills Crushing, Surge Facility & Conveyors\30 Design\Lists\Instrument List\SC610-P-8001_REVB.xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, _
CreateBackup:=False
End With
Proc_Exit:
Application.ScreenUpdating = True
Exit Sub
ErrorHandler:
MsgBox Err.Number & ": " & Err.Description, vbCritical + vbOKOnly, "Error"
Resume Proc_Exit
End Sub
Bookmarks