VBA Lookup from 2 different tables (in different sheets from a single workbook) to make logical conclusion and print result in cell

ouvay

Board Regular
Joined
Jun 9, 2022
Messages
131
Office Version
  1. 2019
Platform
  1. Windows
Hello, I have quite a challenge here .. I am trying to lookup multiple values from 2 different tables from different sheets in a single workbook (different from the one I am applying VBA to)

I wrote this code from scratch but the from so I apologize in advance for the obvious errors or redundancies.

I am getting a
Run-time error '13': Type mismatch
on the code.

I would love any help I could get in resolving this!

TIA!!
VBA Code:
Sub CheckPayments()
    
    Dim wkb         As Excel.Workbook
    Dim Payment     As Excel.Worksheet
    Dim SalesList   As Excel.Worksheet
    Dim wb          As Excel.Workbook
    Dim ws          As Excel.Worksheet
    Dim NewTable    As Object
    Dim a           As Variant
    Dim ProcessID   As Long
    Dim SalesID     As Long
    Dim id          As String
    
    Dim PayOK       As Boolean
    Dim EPay        As Boolean
    Dim Delay       As Boolean
    Dim Cancelled   As Boolean
    Dim TKC         As Boolean
    Dim Tokurei     As Boolean
    Dim NoPay       As Boolean
    Dim EpayR       As Long
    
    Dim DelayR      As Long
    Dim CancelR     As Long
    Dim TKCR        As Long
    Dim TokureiR    As Long
    Dim NoPayR      As Long
    
    Set wkb = Excel.Workbooks("Payment Check Tool.xlsx")
    
    Set Payment = wkb.Worksheets("Processing")
    EpayR = wkb.Worksheets("Processing").ListObjects("Process").ListColumns("Payment")
    DelayR = wkb.Worksheets("Processing").ListColumns("Delay")
    ProcessID = wkb.Worksheets("Processing").ListColumns("Client ID")
    
    Set SalesList = wkb.Worksheets("Sales List Import").ListObjects("SalesList")
    CancelR = wkb.Worksheets("Sales List Import").ListObjects("SalesList").ListColumns("Cancellation")
    TKCR = wkb.Worksheets("Sales List Import").ListObjects("SalesList").ListColumns("Tokurei Release Date")
    TokureiR = wkb.Worksheets("Sales List Import").ListObjects("SalesList").ListColumns("Tokurei")
    NoPayR = wkb.Worksheets("Sales List Import").ListObjects("SalesList").ListColumns("Deposit Date(1st)")
    SalesID = wkb.Worksheets("Sales List Import").ListObjects("SalesList").ListColumns("Purchaser ID")
    
    Set wb = Application.ThisWorkbook
    Set ws = wb.Sheets("Sheet1")
    Set NewTable = ws.ListObjects("Table1")
    Set a = NewTable.DataBodyRange.Value
    
    For i = 1 To UBound(a)
        If a(i, ProcessID) = id Then
            If a(i, EpayR).Value = "E-PAY" Then
                If a(i, DelayR).Value = "DELAY" Or a(i, DelayR).Value = True Then
                    Delay = True
                Else
                    PayOK = True
                    NewTable.Range("B" & i).Value = "OK"
                End If
            ElseIf a(i, SalesID) = id Then
                If a(i, CancelR).Value <> "" Then
                    Cancelled = True
                    NewTable.Range("B" & i).Value = "Cancelled"
                ElseIf a(i, TKCR).Value <> "" Then
                    TKC = True
                    NewTable.Range("B" & i).Value = "TKC Done"
                ElseIf a(i, TokureiR).Value <> "" Then
                    Tokurei = True
                    NewTable.Range("B" & i).Value = "Tokurei"
                ElseIf a(i, NoPayR).Value = "" Then
                    NoPay = True
                    NewTable.Range("B" & i).Value = "NO PAYMENT"
                End If
                EPay = False
                Delay = False
                PayOK = False
                Cancelled = False
                TKC = False
                Tokurei = False
                NoPay = False
            End If
        End If
        
        Exit For
    Next i
    
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

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