0

I have a value in A38 that I would like a button that when clicked will do the equavalent of an Hlookup on my sheet 'Item Database' and return the next value in the column after the value in A38.

Basically a "Next Item" button.

I'm not sure how to tell it to take the value of the cell, do the look up and insert the value of the look up (for the next value down in the column).

Currently i have it pointed at A36 which was a way for me to test the hlookup. when I set it to A38 I dont get an error, but it the cell is blank(after deleting whatever value was in there).

Any advise is appreciated!

Private Sub CommandButton1_Click()
With Range("A38")
.Value = "=HLOOKUP(A36,'Item Database'!A2:A100000, 2,FALSE)"
.Value = .Value
With Range("B38")
.Value = "=VLOOKUP(A38,Item_ID,5,FALSE)"
.Value = .Value
End With
End With
End Sub

1 Answer 1

2

Try this code

Private Sub CommandButton1_Click()
    Range("A38").Value = [HLOOKUP(A38,'Item Database'!A2:A100000,2,FALSE)]
    Range("B38").Value = [VLOOKUP(A38,Item_ID,5,FALSE)]
End Sub
Sign up to request clarification or add additional context in comments.

2 Comments

Perfect, much better way!
@SiddharthRout: I'm sure, you'd have taken the even shorter approach [A38] = [HLOOKUP(A38,'Item Database'!A:A,2,0)]! ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.