根据刚填充的另一个数组单元格值从表中选择列值

时间:2019-06-15 11:08:40

标签: arrays excel-vba-mac

我的问题是: 我创建了一个数组,该数组存储名为cat的excel表中的非重复缺陷类别。 当我更改组combobox1的值时,我想获取类别的出现次数(在arra cat中),并将它们分别存储在nbDef数组中。我该怎么做!

Private Sub ComboBox1_Change()
'tableau nb of defetcs
Dim nbDef() As Integer
ReDim nbDef(0 To UBound(cat)) As Integer
Dim i As Long
    For i = LBound(cat) To UBound(cat)
       For k = 2 To Feuil3.Range("E1").End(xlDown).Offset(1, 0).Row
     nbDef(i) = Application.WorksheetFunction.CountIf(Feuil3.Range("E" & 2, "E" & k), " cat(i)")
    Next k
Next i

End Sub

Private Sub UserForm_Initialize()
'fill Combobox team
Dim i As Long
For i = 2 To Feuil3.Range("H1000000").End(xlUp).Offset(1, 0).Row
x = Application.WorksheetFunction.CountIf(Feuil3.Range("H" & 2, "H" & i), _
Feuil3.Cells(i, 8).Value)
If x = 1 Then
Me.ComboBox1.AddItem Feuil3.Cells(i, 8).Value
End If
Next i
Dim cat() As String

Dim h As Integer
h = 0
'determine  categories number
For i = 2 To Feuil3.Range("E1").End(xlDown).Offset(1, 0).Row
x = Application.WorksheetFunction.CountIf(Feuil3.Range("E" & 2, "E" & i), _
Feuil3.Cells(i, 5).Value)

If x = 1 Then
h = h + 1
End If
Next i
'insert categories to array
ReDim cat(0 To h - 1) As String

Dim m As Integer
m = 0
For i = 2 To Feuil3.Range("E1").End(xlDown).Offset(1, 0).Row
x = Application.WorksheetFunction.CountIf(Feuil3.Range("E" & 2, "E" & i), _
Feuil3.Cells(i, 5).Value)
If x = 1 Then
cat(m) = Feuil3.Cells(i, 5).Value
m = m + 1
End If
Next i
MsgBox (cat(0))


End Sub

0 个答案:

没有答案