VBA-尝试从组合框删除项目时发生错误381

我已经尝试了几个小时来解决这个错误,即搜索解决方案,但是对我来说还不清楚。

  1. 我已成功将项目从Excel导入到组合框(> 19个外观)
  2. 现在我在组合中有重复项。我想通过Excel工作表进行迭代,与Combobox比较并删除不必要的项(单个项除外)
  3. 我有
  

错误381-无法获取Column属性数组索引。

Dim N As Long,K As Long,counter As Long
With Sheets("Główne")
    N = .Cells(Rows.Count,12).End(xlUp).Row
End With

Dim ostatnia As Long

ostatnia = Cells(Rows.Count,11).End(xlUp).Row

For i = 1 To ostatnia
    Range("I" & i + 1).Formula = "=COUNTIFS(L:L,L" & i + 1 & ")"
Next

ComboBox1.Clear
For K = 1 To N
    If Cells(K + 1,9).Value > 19 Then
        ComboBox1.AddItem Sheets("Główne").Cells(K + 1,12).Value
    End If
Next K

Range("I2:I" & ostatnia).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues,Operation:=xlNone,SkipBlanks _
    :=False,Transpose:=False

'############### problem is somewhere below ##############'
For S = 2 To N
    counter = 1
    For iteracjalista = 0 To ComboBox1.ListCount - 1

        If ComboBox1.Column(0,iteracjalista) = Sheets("Główne").Cells(S + 1,12).Value Then

             If Sheets("Główne").Cells(S + 1,9).Value > counter Then
                ComboBox1.RemoveItem 1
                counter = counter + 1
             End If

        End If

    Next iteracjalista
Next S

问题可能出在代码的最后一部分。但是我不知道该如何解决。 你能帮我吗?

mars00721 回答:VBA-尝试从组合框删除项目时发生错误381

代替本守则

For K = 1 To N
    If Cells(K + 1,9).Value > 19 Then
        ComboBox1.AddItem Sheets("Główne").Cells(K + 1,12).Value
    End If
Next K

使用此代码-在填充组合框之前消除重复项

   Dim xList As String,xVal As String

   ' The following populates the ComboBox with Unique Values - No Duplicates
     xList = ""
     ' We are using the colon character ":" as a separator
     ' You may wish to use something else
     For K = 1 To N
        xVal = Cells(K + 1,9).Value
        If xVal > 19 Then
           If InStr(1,xList,":" & xVal,vbTextCompare) = 0 Then
              xList = xList & ":" & xVal
           End If
        End If
     Next K
     xList = Mid(xList,2)  ' Remove the leading : character
     ThisWorkbook.Sheets("Glówne").ComboBox1.List = Split(xList,":")
   ' Done

然后,您可以取出所有现有代码,以从ComboBox中删除重复项...。​​可以删除以下所有内容

'############### problem is somewhere below ##############'
For S = 2 To N
    counter = 1
    For iteracjalista = 0 To ComboBox1.ListCount - 1

        If ComboBox1.Column(0,iteracjalista) = Sheets("Główne").Cells(S + 1,12).Value Then

             If Sheets("Główne").Cells(S + 1,9).Value > counter Then
                ComboBox1.RemoveItem 1
                counter = counter + 1
             End If

        End If

    Next iteracjalista
Next S
本文链接:https://www.f2er.com/3127530.html

大家都在问