I tried using the code below to export from another sheet to a different column in a another sheet and getting an error:
my full code is: (the red code lines will be the ones I am getting the error from)
Public Sub getStat()
Dim cel As Range, wsLog As Worksheet, wsStatus As Worksheet
Dim proc_file As String, wsProc As Worksheet
Dim xlProc As Workbook, found As Range, nextrow As Long
Set wsLog = Workbooks("Request Template.xlsm").Sheets("Log")
Set wsStatus = Workbooks("Request Template.xlsm").Sheets("Status")
wsStatus.UsedRange.Offset(1).ClearContents
wsLog.UsedRange.Offset(5, 0).AutoFilter Field:=5, Criteria1:="<>Disregard Request"
proc_file = "C:\Users\user1\Documents\Projects\Requests\Request Processing Main.xlsm"
Application.ScreenUpdating = False
Set xlProc = Workbooks.Open(proc_file)
Set wsProc = xlProc.Sheets("Status")
For Each cel In Intersect(wsLog.UsedRange.Offset(2).Resize(wsLog.UsedRange.Rows.Count - 1), wsLog.Columns(1)).SpecialCells(xlCellTypeVisible)
nextrow = wsStatus.Cells(wsStatus.Rows.Count, 1).End(xlUp).Row + 1
Set found = wsProc.Columns(1).Find(cel, lookat:=xlWhole)
If Not found Is Nothing Then
wsProc.Range("E" & found.Row).Copy wsStatus.Range("A" & nextrow)
wsProc.Range("B" & found.Row).Copy wsStatus.Range("B" & nextrow)
wsProc.Range("D" & found.Row).Copy wsStatus.Range("D" & nextrow)
wsProc.Range("C" & found.Row).Copy wsStatus.Range("E" & nextrow)
wsProc.Range("A" & found.Row).Copy wsStatus.Range("F" & nextrow)
Next
xlProc.Close 0
wsStatus.UsedRange.RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6, 7, 8), Header:=xlYes
wsLog.UsedRange.AutoFilter
Application.ScreenUpdating = True
wsStatus.Activate
End Sub
Bookmarks