Excel vba:从空行的列中获取范围
我有一列,我想根据从另一列的值提取信息(与空单元格)。
这个问题帮了我很多,但我现在有一个多个空单元格的列,公式不工作…
代码 :
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
显示一个例子的图像:
所以selectVoLTE应该和K1,K3,I7,U6一起组合使用
尝试replace这个:
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