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
您可以尝试使用
Offset
方法将整行获取为:
If Not Rng Is Nothing Then
Me.SearchDisplayX.AddItem Rng.Offset(0, -1).Resize(1, 8).Value
End If