Vba to Find PO and return additional information

vman5781

Board Regular
Joined
Dec 9, 2015
Messages
59
Good morning All,

I am trying to write a VBA to search for either a PO# or Document # and from that return Additional information.

I have a workbook with 2 tabs that this would work with

1st Tab is "Transactions" -- PO # would be -Column "X", Document # is column "V"

2nd Tab is "All Banks" -- Document #would be Column "R", Transaction date- would be -column "G", Vendor Name is column "L", Payment type- would be Column "M", Check # -would be column "J", ACH Transaction # -would be column "O".

3rd Tab would be the userform -- where they would enter the PO# or Document " and it would Return Vendor Name, Document #,Payment type, Payment Date, Check # or Ach Transaction #

Any help with this would be appreciated

Thank you
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Assuming your data like this:

Transactions
Excel Workbook
AUVWX
1Document #PO #
245001123
345002123
445003123
545004124
645005125
745006123
845007124
945008125
1045009123
1145010124
1245011125
Sheet
All Banks
Excel Workbook
AGJLMOR
1Transaction dateCheck #Vendor NamePayment typeACH TransactionDocument #
201-sepch1vend1pay1ach145001
302-sepch2vend2pay2ach245003
403-sepch3vend3pay3ach345005
504-sepch4vend4pay4ach445007
605-sepch5vend5pay5ach545009
706-sepch6vend6pay6ach645001
807-sepch7vend7pay7ach745003
908-sepch8vend8pay8ach845005
1009-sepch9vend9pay9ach945007
1110-sepch10vend10pay10ach1045009
1211-sepch11vend11pay11ach1145001
1312-sepch12vend12pay12ach1245003
1413-sepch13vend13pay13ach1345005
1514-sepch14vend14pay14ach1445007
1615-sepch15vend15pay15ach1545009
1716-sepch16vend16pay16ach1645010
Sheet
3rd Tab
Excel Workbook
ABCDEF
1PO# / Document #
2123
3
4Transaction dateCheck #Vendor NamePayment typeACH TransactionDocument #
543709ch1vend1pay1ach145001
643714ch6vend6pay6ach645001
743719ch11vend11pay11ach1145001
843710ch2vend2pay2ach245003
943715ch7vend7pay7ach745003
1043720ch12vend12pay12ach1245003
1143713ch5vend5pay5ach545009
1243718ch10vend10pay10ach1045009
1343723ch15vend15pay15ach1545009
Sheet




------------------------------------------------------
Put the following code in the events of the sheet

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Address(0, 0) = "A2" Then
    If Target.Count > 1 Then Exit Sub
    If Target.Value = "" Then Exit Sub
    '
    Dim sh1 As Worksheet, sh2 As Worksheet
    Dim r As Range, f As Range, cell As String, dict As Object, ky As Variant, i As Long
    Application.ScreenUpdating = False
    Rows("5:" & Rows.Count).ClearContents
    Set sh1 = Sheets("Transactions")
    Set sh2 = Sheets("All Banks")
    '
    Set dict = CreateObject("scripting.dictionary")
    Set r = sh1.Range("V:V, X:X")
    Set f = r.Find(Target.Value, , xlValues, xlWhole)
    If Not f Is Nothing Then
        cell = f.Address
        Do
          dict.Item(sh1.Cells(f.Row, "V")) = Empty
          Set f = r.FindNext(f)
        Loop While Not f Is Nothing And f.Address <> cell
    End If
    '
    i = 5
    For Each ky In dict.keys
      Set r = sh2.Range("R:R")
      Set f = r.Find(ky, , xlValues, xlWhole)
      If Not f Is Nothing Then
          cell = f.Address
          Do
            Cells(i, "A").Value = sh2.Cells(f.Row, "G")
            Cells(i, "B").Value = sh2.Cells(f.Row, "J")
            Cells(i, "C").Value = sh2.Cells(f.Row, "L")
            Cells(i, "D").Value = sh2.Cells(f.Row, "M")
            Cells(i, "E").Value = sh2.Cells(f.Row, "O")
            Cells(i, "F").Value = sh2.Cells(f.Row, "R")
            i = i + 1
            Set f = r.FindNext(f)
          Loop While Not f Is Nothing And f.Address <> cell
      End If
    Next
  End If
End Sub

------------------------------------------------------
SHEET EVENT
Right click the tab of the sheet (3rd Tab) you want this to work, select view code and paste the code into the window that opens up.


------------------------------------------------------
Return to the sheet (3rd Tab), write the PO or Document number in cell A2 and press enter, the data in row 5 will automatically be filled down.
 
Upvote 0
Dante,

Thank you for this, but it does not seem to work. I have verified the Columns for the data and have pasted the code in -- have typed in a valid PO and /or Document # and nothing happens (after hitting enter)

Thank you
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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