Guinaba
Board Regular
- Joined
- Sep 19, 2018
- Messages
- 217
- Office Version
- 2016
- Platform
- Windows
Hi guys,
Not sure what I am missing in the index-match formula below, I am using ListObject for my range (table).
ws1.Cells(r, c).Value = WorksheetFunction.Index(Range("ColesScanSales"), WorksheetFunction.Match(Vlkup, Range("ColesScanSales").ListColumns(3), 0), 1)
Not sure what I am missing in the index-match formula below, I am using ListObject for my range (table).
ws1.Cells(r, c).Value = WorksheetFunction.Index(Range("ColesScanSales"), WorksheetFunction.Match(Vlkup, Range("ColesScanSales").ListColumns(3), 0), 1)
VBA Code:
Option Explicit
Public Sub Example()
Dim ws1 As Worksheet
Set ws1 = ThisWorkbook.Worksheets("Template")
Dim LRow As Integer
LRow = ws1.Cells(ws1.Rows.Count, "A").End(xlUp).row
Dim LCol As Integer
LCol = ws1.Cells(5, ws1.Columns.Count).End(xlToLeft).Column
Dim VlkupRng As Range
Set VlkupRng = ws1.Range("A5", ws1.Cells(LRow, LCol))
'Declaring worksheet to read scandata
Dim ws4 As Worksheet
Set ws4 = ThisWorkbook.Worksheets("ColesScanData")
Dim ColesScanSales As ListObject
Set ColesScanSales = ws4.ListObjects("tColesScanSalesChilled")
Dim r As Long
Dim c As Long
Dim Vlkup As Variant
For r = 6 To VlkupRng.Rows.Count
For c = 6 To VlkupRng.Columns.Count
Vlkup = ws1.Cells(r, 2) & ws1.Cells(r, 5) & Format(ws1.Cells(5, c), "d/mm/yyyy")
If Cells(r, 5).Value = "Coles Scan Sales" Then
ws1.Cells(r, c).Value = WorksheetFunction.Index(Range("ColesScanSales"), WorksheetFunction.Match(Vlkup, Range("ColesScanSales").ListColumns(3), 0), 1)
End If
Next c
Next r
End Sub