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

Time:04-13

I have the following code that iterates through the sheet and anytime it finds a cell containing the set word, it will target the cell below it and set a value.

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

I'm trying to get it so that a input box pops up every time to let the user set the value for each time it finds the set word. The snippet below is what I'm trying to add to the code above. I just can't figure out how to integrate it.

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

CodePudding user response:

Well, you just need to put the inputbox inside the for loop as below.

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
  • Related