如果单元格值与组合框项目匹配,则复制整行

时间:2017-10-16 22:04:17

标签: excel vba combobox

我尝试实现的目标如下:

我有以下用户表单: Userform lay-out

组合框中的项目已通过以下代码添加:

cbbAirline.List = Array("NAX", "VLG", "QTR")

现在我必须根据组合框中的选项从工作表中进行过滤。完成过滤后,我必须将整个行复制到新工作表。

我已经尝试过以下代码,但它一直在说我找不到任何内容:

Dim findmatch As Object
Dim lastcell As Integer

Set findmatch = ThisWorkbook.Sheets("FlightList").Range("J:J").Find( _
               What:=UserForm1.cbbAirline.Value, LookIn:=xlValues)
If Not findmatch Is Nothing Then
    lastcell = ThisWorkbook.Sheets(UserForm1.cbbAirline.Value). _
               Cells(100000, 7).End(xlUp).row 'here find a way to locate last cell in sheet that has your name.. 
                                               ' it keeps returning me 1 but other than that it works fine
    ThisWorkbook.Sheets(UserForm1.cbbAirline.Value).Range( _
      Cells(lastcell, 1), Cells(lastcell, 40)) = _
       Range(Cells(findmatch.row, 1), Cells(findmatch.row, 40)).Value
Else
    MsgBox "not found"

请有人帮我这个。

0 个答案:

没有答案