Macro Excel pour rechercher une valeur dans une colonne et renvoyer une valeur sur la même ligne à partir d'une autre colonne dans la boîte de message
Je suis en train d'écrire une macro qui invite l'utilisateur à entrer une valeur et d'effectuer les opérations suivantes:
- Search for the value in column B and select the first cell where the value is found
- Return the correspondong value in column L and M of the selected cell's row within a message box
- Then once the user hits "ok", the macro will find and select the next cell in column B with the search criteria, and repeat the above steps
- Once all of the cells with the search criteria in column B have been searched and found, a message box will communicate that all matches have been found and close loop
Ci-dessous le code que j'ai commencé avec, et d'être un débutant avec VB, je ne peux pas comprendre pourquoi ma boucle ne fonctionne pas correctement... s'il vous Plaît aider!
Sub Macro1()
Dim response As String, FndRow As Long, NoMatch As Boolean, LastRow As Long
response = InputBox("Please enter the Column Name to find matching Source File Field Name.")
If response = "" Then Exit Sub
On Error Resume Next
Range("B5").Select
NoMatch = False
LastRow = 0
Do Until NoMatch = True
FndRow = Cells.Find(What:=response, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Row
If FndRow = 0 Then
MsgBox response & " could not be found."
NoMatch = True
ElseIf FndRow < LastRow Then
MsgBox "All " & response & " matches have been found."
NoMatch = True
Else
Range("B" & FndRow).Select
MsgBox "Source File Name: " & Range("L" & FndRow).Value & vbNewLine & "File Column Name: " & Range("M" & FndRow).Value
LastRow = FndRow
End If
Loop
End Sub
Vous devez vous connecter pour publier un commentaire.
Je voudrais utiliser un filtre au lieu de trouver la boucle:
votre Trouver agit de façon étrange, parce que vous êtes à la recherche pour le match 'horizontale'. Vous avez besoin d'utiliser SearchOrder:=xlByColumns