I use the below code in a user form, I have bold red font on the code to make the results font turn Red below, It selects the found address and highlights the font red, but I would like to also filter the results on whichever worksheet the results are found.
>>> moved Your Ask an Excel Question to VBA Macros <<<
>>> use code - tags <<<
>>> moved Your Ask an Excel Question to VBA Macros <<<
>>> use code - tags <<<
Code:
Sub Copy_Paste_Result()
'Copy the results of the selection in the listbox and paste to a results sheet
'Created by Gary Carpenter
On Error GoTo ErrorHandler:
Dim strAddress As String
Dim strSheet As String
Dim strCell As String
Dim l As Long
Dim lLastRow As Long
Const sRESULTS As String = ("Orders") 'Can be changed to the name of your sheet
Worksheets("Orders").Visible = True
For l = 0 To ListBox_Results.ListCount
If ListBox_Results.Selected(l) = True Then
strAddress = ListBox_Results.List(l, 1)
strSheet = Replace(Mid(strAddress, 1, InStr(1, strAddress, "!") - 1), "'", "")
Worksheets(strSheet).Select
Worksheets(strSheet).Range(strAddress).Select
' below line is that red
Worksheets(strSheet).Range(strAddress).Font.color = vbRed
' above line is that red
Worksheets(strSheet).Range(strAddress).Select
' With ActiveSheet
' f_FindAll.TextBox_Results1.Value = .Cells(.Range(strAddress).Row, 3).Value
' f_FindAll.Textbox_Results2.Value = .Cells(.Range(strAddress).Row, 4).Value
' End With
'Copy/Paste results at end of results sheet
With Worksheets(sRESULTS)
'Find next blank cell in results sheet
'lLastRow = .Range("A" & .Rows.Count).End(xlUp).Row + 2
'Paste results in the result sheet
'.Range("A" & lLastRow).Value = Worksheets(strSheet).Range(strAddress).Value
'Optional columns
'Cell address
' .Range("B" & lLastRow).Value = strAddress
'Time Stamp
'.Range("C" & lLastRow).Value = Now
End With
GoTo EndLoop
End If
Next l
EndLoop:
ErrorHandler:
Exit Sub
Resume Next
End Sub
Last edited by a moderator: