I have an userform on which you can edit the text in cells of an excel sheet. Since the inputbox doesn't have a skip button, I made an Userform where you can search a value in the whole workbook and replace it with another value entry. The thing is I want to edit the found values one by the other and not all at the same time. I have the following code but what this does is, it replaces every first occurance of the found value in every sheet. How could I change the logic that it replaces the values from first sheet then from second and so on.
Dim ws As Worksheet
Dim Loc As Range
Dim StrVal As String
Dim StrRep As String
Private Sub CommandButton1_Click()
StrVal = UserForm1.TextBox3.Text
If Trim(StrVal) = "" Then Exit Sub
For Each ws In ThisWorkbook.Worksheets
With ws.UsedRange
Set Loc = .Cells.Find(What:=StrVal)
If Not Loc Is Nothing Then
'Do Until Loc Is Nothing
Application.Goto Loc, False
StrRep = TextBox1.Text
If Not StrRep = "" Then
Loc.Value = StrRep
Set Loc = .FindNext(Loc)
Else
Exit Sub
End If
'Loop
End If
End With
Set Loc = Nothing
Next
End Sub
I created this which works but has now the problem that it skips though even if there is no existing value.
Set ws = ThisWorkbook.ActiveSheet
Set Loc = ws.Cells.Find(what:=StrVal)
If Not Loc Is Nothing Then
Application.Goto Loc, False
StrRep = TextBox1.Text
If Not StrRep = "" Then Loc.Value = StrRep
Else
Worksheets(ActiveSheet.Index + 1).Select
End If
Try this