'Find a value and next cell

I'm trying to make a excel macro to find a name in a table, let's say I want to find Mark, and want it with an input box, that one I know how to do:

InputBox("Qual o Nome?")

But I would like that there is a list to choice from, instant of having to write the name every time, so lets say the names are in Row C (let's say C4:C15).

After finding the name (imagine the name is in C5) I want it to select next column (in this case D5), and insert on that cell a value, that will ask in a new InputBox.

Right now I'm having some trouble doing the looking for the name and select new column cell according to the name position.

So this is what I got so far:

Private Sub CommandButton1_Click()

    'This one i cant figure it out
Dim Range As Variant
Range = InputBox("Qual o Char?") 'Here is where i say the name
Cells(Range, 1).Value = InputBox("Focus actual?") 'Here i want it to insert in the cell right, after the name it looked for
Cells(Range, 2).Value = Now() 'Here i want it to insert in 2 cell right, after the name it looked for

End Sub


Solution 1:[1]

Your code will look something like:

Private Sub CommandButton1_Click()

    'Declare the variables you will need to store the found range and two user inputs
    Dim foundRange as Range
    Dim userInput1 as String
    Dim userInput2 as String
   
    'get your user input into variables
    userInput1 = InputBox("Qual o Char?") 'Here is where i say the name
    userInput2 = InputBox("Focus actual?")

    'Use the Found method of the Range object to find your userInput
    foundRange = Sheet1.Range("A1:Z500").Find(userInput, lookin:=xlValues)

    'Use Offset() to move around and place values:
    foundRange.Offset(0,1).Value = userInput2 'Here i want it to insert in the cell right, after the name it looked for
    foundRange.Offset(0,2).Value = Now() 

End Sub

Likely some more work will be needed to validate your user input or do something different if Range.Find() comes up empty, but this should get you in the ballpark.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JNevill