VBA Userform as Inputbox

◇◆丶佛笑我妖孽 提交于 2019-12-02 00:35:24

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!