VBA Userform as Inputbox

后端 未结 1 1180
遇见更好的自我
遇见更好的自我 2021-01-21 15:36

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

1条回答
  •  迷失自我
    2021-01-21 16:13

    Try this

    For Each ws In ThisWorkbook.Worksheets
        Application.Goto ws.Range("A1"), True
        Set Loc = ws.Cells.Find(What:=strVal, After:=ws.Cells(Rows.Count, Columns.Count), SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False) 'You can change MatchCase to True for better checking
        If Not Loc Is Nothing Then
            strFirstAddress = Loc.Address
            changeBool = False
            Do
                strRep = Me.TextBox1.Text
                If Not strRep = "" Then
                    Application.Goto ws.Range(Loc.Address), False
                    If MsgBox("Do you want to change the value of cell " & Loc.Address(0, 0) & " of worksheet " & ws.Name & "?", vbYesNo + vbQuestion, "Question") = vbYes Then
                        Loc.Value = strRep
                        If Loc.Address = strFirstAddress Then
                            changeBool = True
                        Else
                            changeBool = False
                        End If
                    Else
                        changeBool = False
                    End If
                End If
                Set Loc = ws.Cells.FindNext(After:=Loc)
                If Not Loc Is Nothing Then
                    If Loc.Address = strFirstAddress Then Set Loc = Nothing
                End If
                If Not Loc Is Nothing And changeBool = True Then strFirstAddress = Loc.Address
            Loop While Not Loc Is Nothing
        End If
    Next ws
    

    0 讨论(0)
提交回复
热议问题