用于搜索值组合的VBA脚本

时间:2014-06-24 09:21:09

标签: vba combinations

我希望有人可以帮我解决以下问题。 我在每一行都有一张表格,其中包含客户/病人记录(从第3行开始)和56列医疗数据(条件,药物等)以进行搜索。我有一个带有多个组合框的用户表单来选择项目或项目组合我搜索。我制作了一个脚本来搜索项目的组合。问题是结果甚至不应该接近结果。

Private Sub cmdCOMBI_Click()
Dim COMBIRange As Range
Dim LastRow As Long
Dim LastCol As Long
Dim cbo1 As String
Dim cbo2 As String
Dim cbo3 As String
Dim Par1 As Integer
Dim Par2 As Integer
Dim Par3 As Integer
Dim conb As Integer

LastRow = Worksheets("SOURCE").Cells(Rows.Count, 1).End(xlUp).Row
Set COMBIRange = Worksheets("SOURCE").Range("A2:BO" & LastRow)

If Not cboINCL1.TEXT = "" Then
cbo1 = cboINCL1.Value
Par1 = 1
Else
cbo1 = "--"
Par1 = 0
End If

If Not cboINCL2.TEXT = "" Then
cbo2 = cboINCL2.Value
Par2 = 1
Else
cbo2 = "--"
Par2 = 0
End If

If Not cboINCL3.TEXT = "" Then
cbo3 = cboINCL3.Value
Par3 = 1
Else
cbo3 = "--"
Par3 = 0
End If

ParTotal = Par1 + Par2 + Par3
conb = 0

For iR = 3 To LastRow
    For iC = 11 To 67
      If Worksheets("SOURCE").Cells(iR, iC).Value = cbo1 Or Worksheets("SOURCE").Cells(iR, iC).Value = cbo2 Or Worksheets("SOURCE").Cells(iR, iC).Value = cbo3 Then
        INC = INC + 1
        End If
        Next iC

If INC = ParTotal Then
conb = conb + 1
End If
Next iR


  FormMENU.tboResIN.Value = conb
End Sub

任何人都知道我做错了什么?

提前谢谢!

1 个答案:

答案 0 :(得分:0)

好的,我自己发现了这个问题。我忘了在每个新行的开头将INC声明为0。

For iR = 3 To LastRow
INC = 0
For iC = 11 To 67