arraysvbaexcelarray-key-exists

Check if value exist into two-dimensional tab (array, vb)


I creating tab(x,y) with values:

Dim CostCatTab() As Variant
Dim tabSize As Long

For m = 3 To CCRLastColumn

    CostCategory = wsSum.Cells(CostCagRow, m).Value
    Value = wsSum.Cells(CostCagRow, m).Value

    tabSize = tabSize + 1
    ReDim Preserve CostCatTab(1 To 2, 1 To tabSize)
    CostCatTab(1, tabSize) = CostCategory
    CostCatTab(2, tabSize) = m

Next

Into second loop I want to check if current item (currentCT) is into CostCatTab.CostCategory.

If yes, then I want to display appropriate m value for CostCategory.

For h = 10 To x_rows
    currentCT = wsCal.Range("M" & h).Value

Next

Solution

  • I did:

     For h = 10 To x_rows
            currentCT = wsCal.Range("M" & h).Value
    
        For b = LBound(CostCatTab, 2) To UBound(CostCatTab, 2)
            If CostCatTab(1, b) = currentCT Then
                wsCal.Range("N" & n).Value = wsCal.Range("K" & n).Value * wsSum.Cells(40, CostCatTab(2, b))
                Exit For
            End If
        Next b
    
     Next h