Hello,
Im trying to populate cells using a an index match function within VBA, I know how to do this with in a cell but cant seem to get it to work in vba. The code segment below is what i have so far, the underlined part is the line i am haivng trouble with. Thanks for help it would be much appriciated.
Sub Merge()
Dim ws1, ws2 As Worksheet
Dim wb As Workbook
Dim a, b, PSum, StdHrs, LastRow As Integer
Set wb = ThisWorkbook
Set ws1 = wb.Sheets("DOWNLOAD2")
Set ws2 = wb.Sheets("JOHN")
a = 2
b = 2
PSum = 0
StdHrs = 0
Application.ScreenUpdating = False
LastRow = ws2.UsedRange.Rows.Count
For a = 2 To LastRow
If ws2.Cells(a, 4).Value <> ws2.Cells(a + 1, 4).Value Then
ws2.Cells(a, 22) = Application.WorksheetFunction.Index(Sheets("DOWNLOAD").Range("A:Q"), Application.WorksheetFunction.Match((ws2.Cells(a,3).Value) & (ws2.Cells(a,4).Value), (Sheets("DOWNLOAD").Range("A:A")) & (Sheets("DOWNLOAD").Range("C:C")), 0), 16)
End If
Next a
Application.ScreenUpdating = True
End Sub
Im trying to populate cells using a an index match function within VBA, I know how to do this with in a cell but cant seem to get it to work in vba. The code segment below is what i have so far, the underlined part is the line i am haivng trouble with. Thanks for help it would be much appriciated.
Sub Merge()
Dim ws1, ws2 As Worksheet
Dim wb As Workbook
Dim a, b, PSum, StdHrs, LastRow As Integer
Set wb = ThisWorkbook
Set ws1 = wb.Sheets("DOWNLOAD2")
Set ws2 = wb.Sheets("JOHN")
a = 2
b = 2
PSum = 0
StdHrs = 0
Application.ScreenUpdating = False
LastRow = ws2.UsedRange.Rows.Count
For a = 2 To LastRow
If ws2.Cells(a, 4).Value <> ws2.Cells(a + 1, 4).Value Then
ws2.Cells(a, 22) = Application.WorksheetFunction.Index(Sheets("DOWNLOAD").Range("A:Q"), Application.WorksheetFunction.Match((ws2.Cells(a,3).Value) & (ws2.Cells(a,4).Value), (Sheets("DOWNLOAD").Range("A:A")) & (Sheets("DOWNLOAD").Range("C:C")), 0), 16)
End If
Next a
Application.ScreenUpdating = True
End Sub