Hello guys!
I'm pretty new to VBA and macros, and I need your help
Basically, I was using this code to search my whole workbook (contains 5+ sheets) for a specific text (name for example).
I didn't write it myself, I've just put it together using various examples I've found on this forum.
I have two questions/problems I need help with:
1. How can I copy results to, for example, 10th row in Sheet1? My code copies results to 2nd row in Sheet1.
2. Is it possible to print/show value of whole row where specific text was found in a message box, instead of copying results to Sheet1? Message box from my code just shows exact cell where searched text was found.
Thank you very much in advance!
I'm pretty new to VBA and macros, and I need your help
Basically, I was using this code to search my whole workbook (contains 5+ sheets) for a specific text (name for example).
Code:
Public Sub FindText()'Run from standard module, like: Module1.
'Find all data on all sheets!
'Do not search the sheet the found data is copied to!
'List a message box with all the found data addresses, as well!
Dim ws As Worksheet, Found As Range
Dim myText As String, FirstAddress As String
Dim AddressStr As String, foundNum As Integer
myText = InputBox("Unesi tekst za pretragu (ime/prezime)", "Pretraga")
If myText = "" Then Exit Sub
Worksheets("Odluke, početna").Range("A1:XX200").Delete
For Each ws In ThisWorkbook.Worksheets
With ws
Set Found = .UsedRange.Find(What:=myText, LookIn:=xlValues, LookAt:=xlPart, MatchCase:=False)
If Not Found Is Nothing Then
FirstAddress = Found.Address
Do
foundNum = foundNum + 1
AddressStr = AddressStr & .Name & " " & Found.Address & vbCrLf
Set Found = .UsedRange.FindNext(Found)
Found.EntireRow.Copy _
Destination:=Worksheets("Sheet1").Range("A65536").End(xlUp).Offset(1, 0)
Loop While Not Found Is Nothing And Found.Address <> FirstAddress
End If
myNext:
End With
Next ws
If Len(AddressStr) Then
MsgBox "Ime/prezime " & myText & " pronađeno na:" & vbCr & _
AddressStr, vbOKOnly, myText & ""
Else:
MsgBox "Ime/prezime " & myText & " nije pronađeno", vbExclamation
End If
End Sub
I didn't write it myself, I've just put it together using various examples I've found on this forum.
I have two questions/problems I need help with:
1. How can I copy results to, for example, 10th row in Sheet1? My code copies results to 2nd row in Sheet1.
2. Is it possible to print/show value of whole row where specific text was found in a message box, instead of copying results to Sheet1? Message box from my code just shows exact cell where searched text was found.
Thank you very much in advance!