Trying to use index match method

Eric Penfold

Active Member
Joined
Nov 19, 2021
Messages
431
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
All this works correct except for the Index match method say`s run time error 438?
Anyone know why?

VBA Code:
Option Explicit
Sub VLookup()

    Dim SrcReD As Workbook, Alton As Workbook, Cov As Workbook, Basildon As Workbook, wb As Workbook, BName As Workbook
    Dim ws     As Worksheet, SrcRed_ws As Worksheet
    Dim SrcLRow As Long, wsLCol As Long, col_wsRed As Long, ColOn As Long, ColRd As Long
    Dim r      As Integer, c As Integer
    Dim LRow   As Long, LCol As Long
    Dim Answer As Long
    Dim FileToOpen As Variant, arrRng As Variant
    Dim SrcRed_Rng As Range, DesRng As Range, Rng As Range, TableArray As Range
    Dim BlCell As Boolean
    Dim myDate As String
    Dim Result As Variant
    BlCell = False
    
    With Application
        .EnableEvents = False
        .ScreenUpdating = False
        .DisplayAlerts = False
        .Calculation = xlCalculationManual
    End With
    
    Answer = MsgBox("BO Report?", vbYesNo + vbQuestion, "Is it a BO Report")
    If Answer = vbNo Then Exit Sub
    If Answer = vbYes Then
        
        Depot_Name wb
        
        Set BName = wb
        
        FileToOpen = ("S:\PURCHASING\Stock Control\Reports\Back Order Admin\Back Order Release Date.xlsx")
        Workbooks.Open FileToOpen
        Set TableArray = ActiveWorkbook.ActiveSheet.Range("A:M")
        Set SrcReD = Workbooks("Back Order Release Date.xlsx")
        Set SrcRed_ws = SrcReD.Sheets("Sheet1")
        SrcLRow = SrcRed_ws.Cells(Rows.Count, 1).End(xlToLeft).Row
        Set SrcRed_Rng = SrcRed_ws.Range("A2:B" & SrcLRow)
        wb.Activate
        myDate = Format(Date, "mmm")
        Set ws = wb.Worksheets(myDate)
        Set Rng = ws.Range("1:1")
        ColOn = WorksheetFunction.Match("Order Number", Rng, 0)
        ColRd = WorksheetFunction.Match("Back Order Release Date", Rng, 0)
        LRow = ws.Cells(Rows.Count, 2).End(xlUp).Row
        LCol = ws.Cells(Columns.Count, 2).End(xlUp).Column
        
        If ws.Name <> "Summary" And ws.Name <> "Trend" And ws.Name <> "Supplier BO" And ws.Name <> "Diff Depot" _
            And ws.Name <> "BO Trend WO" And ws.Name <> "BO Trend WO 2" And ws.Name <> "Different Depot" Then
            
            For r = 1 To LRow
                For c = 1 To LCol
                    
                    ws.Cells(r, c).Value = WorksheetFunction.VLookup(ws.Cells(r, 3), _
                                 TableArray.WorksheetFunction.Match(SrcRed_Rng.Cells(1, c), Rng, 0), 0)
                Next c
            Next r
            
            ws.Range("N2:N" & LRow) = Application.WorksheetFunction.Days360(Range("A"), Range("M"), False)
            
        End If
        
        SrcReD.Close
        
    End If
    
    With Application
        .EnableEvents = True
        .ScreenUpdating = True
        .DisplayAlerts = True
        .Calculation = xlCalculationAutomatic
    End With
    
End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
You can't use TableArray.WorksheetFunction since a range doesn't have a WorksheetFunction method.

Also, I suspect this:

Code:
SrcLRow = SrcRed_ws.Cells(Rows.Count, 1).End(xlToLeft).Row

was meant to use xlUp not xlToLeft, which is pointless.
 
Upvote 0
What did you alter it to?

FYI it's also not generally a good idea to name your routines the same as Excel methods
 
Upvote 0
More issues: Range("A") and Range("M") are unlikely to be correct unless those are the names that you gave to two ranges?
 
Upvote 0
What did you alter it to?

FYI it's also not generally a good idea to name your routines the same as Excel methods
I`ve changed the code name. And altered the Table array to a range. Also changed the Range "A" and Range "M" to the names given.
 
Last edited:
Upvote 0
Here is Watch window as you can see it`s correct? So struggling still say`s error 438??
1689146937718.png
 
Upvote 0
The table array already was a range. What I said was that TableArray.WorksheetFunction.Match is invalid (and will cause a 438 error) because the worksheetfunction method doesn't belong to the Range object. I think it's just a typo and that first dot should be a comma:

VBA Code:
WorksheetFunction.VLookup(ws.Cells(r, 3), _
                                 TableArray, WorksheetFunction.Match(SrcRed_Rng.Cells(1, c), Rng, 0), 0)
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,183
Members
452,615
Latest member
bogeys2birdies

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