我有一个列,我想根据另一列的值从(使用空单元格)中提取信息
这个question给了我很多帮助,但我现在有一个包含多个空单元格的列,并且公式不起作用......
代码:
Private Sub techCombo_Change()
Dim ws As Worksheet
Dim rFound As Range
Dim cCmbBox As MSForms.ComboBox
Set cCmbBox = ActiveWorkbook.Sheets(1).custCombo
cCmbBox.Clear
With Me.cmbSheet
If .ListIndex = -1 Then Exit Sub
Set ws = ActiveWorkbook.Sheets(.Text)
End With
With Me.techCombo
If .ListIndex = -1 Then Exit Sub
Set rFound = ws.Columns("A").Find(.Text, ws.Cells(ws.Rows.Count, "A"), xlValues, xlWhole)
End With
If Not rFound Is Nothing Then
If Trim(Len(rFound.Offset(2, 1).Text)) = 0 Then
cCmbBox.AddItem rFound.Offset(1, 1).Value
Else
cCmbBox.List = ws.Range(rFound.Offset(1, 1), rFound.Offset(1, 1).End(xlDown)).Value
End If
End If
End Sub
答案 0 :(得分:1)
尝试替换它:
If Not rFound Is Nothing Then
If Trim(Len(rFound.Offset(2, 1).Text)) = 0 Then
cCmbBox.AddItem rFound.Offset(1, 1).Value
Else
cCmbBox.List = ws.Range(rFound.Offset(1, 1), rFound.Offset(1, 1).End(xlDown)).Value
End If
End If
用这个:
If Not rfound Is Nothing Then
LastRow = Ws.Cells(Ws.Rows.Count, rfound.Column + 1).End(xlUp).Row
j = rfound.Row
i = 1
Do While j <= LastRow And rfound.Offset(i) = ""
If rfound.Offset(i, 1) <> "" Then
cCmbBox.AddItem rfound.Offset(i, 1)
End If
i = i + 1
j = j + 1
Loop
End If