2017-01-13 1 views
0

I 탭을 생성 (X, Y)에 존재하는 경우 : I 검사 할체크 값이 값 이차원 탭 (배열 VB)

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 

초 루프 경우 현재 항목 (currentCT) CostCatTab.CostCategory입니다.

는 경우 예, 그때에 CostCategory에 대한 표시 적절한 m의 값을합니다.

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

Next 
+1

마지막'tabSize'이 CCRLastColum'- 보존하지 않고 루프가 시작되기 전에 하나의 재정의하십시오를 사용하는 것이 빠를 것이다 2'. 'tabSize'는 항상'm-2'입니다. 여기에 하나의 변수 만 사용할 수 있습니다. –

+0

'CostCatTab (2, tabSize) = m' 행이 'CostCatTab (2, tabSize) = Value'가 아니어야합니까? –

+0

@ Vincent -> 변경하는 방법은 무엇입니까? code – 4est

답변

0

내가 한 :

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