This has been driving me nuts for awhile. What I'm trying to do is, in theory, fairly simple.
I have a list of names I care about. This list of names is in a named range. I'd like to open a report, see if the name in a particular column is on the list, and if it is, move it over. Otherwise, don't move it over. I've tried putting the list in a range, in a variant, just referencing it directly. I've tried loops, conditionals, loops within loops, worksheet functions, no worksheet functions, ubound and lbound, isnumeric, deleting the rows and moving everything over, and more. I just can't get it to work. Current set of code:
Dim i As Long
Dim j As Long
Dim MSCFundList As Range
CABReconFilePath = Range("CABReconFilePath")
Set MSCFundList = Range("MSCFundList")
Workbooks.Open Filename:=CABReconFilePath
Set CabReport = ActiveWorkbook
Workbooks.Open Filename:=MSCReportPath
Set MSCReport = ActiveWorkbook
Set MSTab = MSCReport.Sheets(1)
LastRowMSC = MSTab.Range("A" & Rows.Count).End(xlUp).Row
j = 2 ' count the row offset in the destination range
'Getting in the headers
Set RngMSC = MSTab.Range("A1:AZ1")
CabReport.Sheets("MS").Range("A1:AZ1").Value = RngMSC.Value
For i = 2 To LastRowMSC
Debug.Print LastRowMSC
If IsNumeric(Application.Match(range("E" & I), MSCFundList, 0)) Then
Set RngMSC = MSTab.Range("A" & i & ":AZ" & i)
CabReport.Sheets("MS").Range("A" & j & ":AZ" & j).Value = RngMSC.Value
j = j + 1
End If
Next
I'm at my wits' end. I've gone over a few different stack overflow posts - the most promising one was Check if a value is in an array or not with Excel VBA
Edit: Expected behavior: Only some rows move over. Actual behavior: No rows move over. Headers are moving over correctly.