Filter source WB with multiple criteria using VBA instead of Excel function

adambc

Active Member
Joined
Jan 13, 2020
Messages
412
Office Version
  1. 365
Platform
  1. Windows
Cell B1 = Firstname
Cell B2 = Surname
Cell B3 = =FILTER('https://sharepointpath/[SOURCEWB.xl...POINTPATH/[SOURCEWB.xlsx]SHEETNAME'!$K:$K=B2),"")

... which returns an array of values from column A of the source WB if column Jof the source WB = B1 AND column Kof the source WB = B2

Works perfectly but I'd like to rewrite this in VBA for consistency (B1 & B2 are populated by a VBA Sub using InputBoxes)

But can't get my head round how to do it?

Thanks ...
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
IGNORE!

It's wonderful what a good night's sleep does, is it?!

This is my solution ...

VBA Code:
Sub IDList()

wbSourceName = "SOURCEWB.xlsx"
wbSourcePathName = "SHAREPOINTPATH" & wbSourceName
Set wbSource = Workbooks.Open(wbSourcePathName)

lrSource = wbSource.Sheets(1).Range("A" & Rows.Count).End(xlUp).Row

With wbSource

    For i = 2 To lrSource

lrIDList = ThisWorkbook.Sheets(1).Range("D" & Rows.Count).End(xlUp).Row
nrIDList = lrIDList + 1

        If .Sheets(1).Cells(i, 10) = ThisWorkbook.Sheets(1).Cells(1, 2) And .Sheets(1).Cells(i, 11) = ThisWorkbook.Sheets(1).Cells(2, 2) Then
            ThisWorkbook.Sheets(1).Cells(nrIDList, 4).Value = .Sheets(1).Cells(i, 1).Value
        End If

    Next i

End With

wbSource.Close

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top