如何显示搜索结果的一整行excel vba

3wabscal  于 2023-04-22  发布在  其他
关注(0)|答案(1)|浏览(141)
CINorRC = InputBox("Entrez un CIN ou RC correct.")
If StrPtr(CINorRC) = 0 Then
    Exit Sub
ElseIf CINorRC = "" Then
    MsgBox ("Err...")
End If

    With Me.SearchDisplayX
    .AddItem
    .List(.ListCount - 1, 0) = "CIN/RC"
    .List(.ListCount - 1, 1) = "ART"
    .List(.ListCount - 1, 2) = "Nom"
    .List(.ListCount - 1, 3) = "Nature"
    .List(.ListCount - 1, 4) = "LI"
    .List(.ListCount - 1, 5) = "**"
    .List(.ListCount - 1, 6) = "DP"
    .List(.ListCount - 1, 7) = "OBS"
    End With

If Trim(CINorRC) <> "" Then
    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Sheets
    With ws.Range("A2:L999")
            Set Rng = .Find(What:=CINorRC, _
                            After:=.Cells(.Cells.Count), _
                            LookIn:=xlValues, _
                            LookAt:=xlWhole, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlNext, _
                            MatchCase:=False)
    If Not Rng Is Nothing Then
    Application.Goto Rng, True
    Me.SearchDisplayX.AddItem Rng.rows
    End If
    End With
    Next ws
    If Not Rng Is Nothing Then
        MsgBox "Nothing found"
    End If
End If

下面是整个代码
名为SearchDispaly的列表框仅显示CINorRC值,而不显示第一个单元格中具有该值的整个行
如果你看到其他的代码问题,我会很感激你帮助我解决它们〈3

bvuwiixz

bvuwiixz1#

您可以尝试使用Offset方法获取整行:

If Not Rng Is Nothing Then
        Me.SearchDisplayX.AddItem Rng.Offset(0, -1).Resize(1, 8).Value           
 End If

相关问题