I'm trying to delete a bunch of tags from a master list and I am having issues with the confirmation part. I managed to make the whole deleting process work, but I'm having trouble while trying to confirm that the tags have actually been deleted.
I have 2 textbox, one where the user enters his input, and another showing the results. I would like the second one to show either "Item Was Removed" or "Item could not be found".
I can't seem to figure out how to.
Here's my code:
Private Sub BtnSubmit_Click()
TxtResult.Value = ""
Multi_FindReplace
End Sub
Public Sub Multi_FindReplace()
Number() = Split(TxtNumbers.Text, vbNewLine)
'Loops to find the asset tags through the list
For x = LBound(Number()) To UBound(Number())
'Confirms the Asset Tag is 7 characters
If Len(Number(x)) = 7 Then
For Each sht In ActiveWorkbook.Worksheets
'Deletes the actual Asset Tag from the list
sht.Cells.Replace What:=Number(x), Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False
Next
Else
TxtResult.Value = TxtResult.Value & vbNewLine & "Invalid C#"
End If
Next
End Sub
Public Sub Results()
If TxtResult.Value = "" Then
TxtResult.Value = Number(x) & " Was Removed!"
Else
TxtResult.Value = TxtResult.Value & vbNewLine & Number(x) & " Was Removed! "
End If
End Sub
Thank you!
You should publicly declare x as integer and your number() array at the top of your module. Then call the Results Sub after you successfully remove the asset tag from all sheets of the ActiveWorkbook.
I haven't tested the code, but it should look like this:
Public x as Integer
Public Number()
[...]
If Len(Number(x)) = 7 Then
For Each sht In ActiveWorkbook.Worksheets
'Deletes the actual Asset Tag from the list
sht.Cells.Replace What:=Number(x), Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False
Next
Results
Else
See the Calling Sub and Function Procedures help file for details.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.