迭代查找文本然后打开输入框并将值设置为用户输入

Iterate to find text then open inputbox and set value to user input

我有以下代码遍历 sheet,只要它找到包含设置词的单元格,它就会定位到它下面的单元格并设置一个值。

Dim i As Integer
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To Lastrow
        If (Cells(i, 1).Value) Like "ACCOUNT*" Then Cells(i + 1, 1).Value = "..."
    Next

我想搞定,每次都弹出一个输入框,让用户在每次找到set word的时候设置值。下面的代码片段是我要添加到上面的代码中的内容。我只是不知道如何整合它。

Dim AccountDesc As Variant
AccountDesc = InputBox("Enter the account description.", "Account Description")

好吧,你只需要将输入框放在 for 循环中,如下所示。

Sub test()

    Dim i As Integer
    Dim Lastrow As Long
    Dim AccountDesc As Variant
    Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To Lastrow
         If (Cells(i, 1).value) Like "ACCOUNT*" Then
              AccountDesc = InputBox("Enter the account description.", "Account Description")
              Cells(i + 1, 1).value = AccountDesc
         End If
    Next
   
End Sub