I am trying (unsucessfully) to create a macro that opens an InputBox and allows the user to enter a document name. Then I want to select the cell in a single column that contains that input. There are no duplicates.
Thanks
I am trying (unsucessfully) to create a macro that opens an InputBox and allows the user to enter a document name. Then I want to select the cell in a single column that contains that input. There are no duplicates.
Thanks
This might work for you.
[VBA]Sub test()
Dim userInput As String
Dim rowFound As Variant
Dim dataColumn As Range
Set dataColumn = ThisWorkbook.Sheets("sheet1").Range("A:A"): Rem adjust
Do
userInput = Application.InputBox(userInput & "Which document do you want?", Type:=2)
If userInput = "False" Then Exit Sub: Rem cancel pressed
rowFound = Application.Match(userInput, dataColumn, 0)
If IsError(rowFound) Then userInput = "That document not found. Try again." & vbCr
Loop Until Right(userInput, 1) <> vbCr
dataColumn.Parent.Activate
dataColumn.Cells(rowFound, 1).Select
End Sub[/VBA]
Thanks for the help...
It does not seem to find the document, which is a number not text, when I change "Dim userInput As String" to "Dim userInput As Integer" I get "Type Mismatch" on this line
If userInput = "False" Then Exit Sub: Rem cancel pressed
The looping structure et.al is dependent on userInput being a string. Leave userInput as string and change
[VBA]rowFound = Application.Match(Val(userInput), dataColumn, 0) [/VBA]
Works Like A Charm!!!!
Thanks Mike....
You're welcome.
Hi John,
If your question is answered, please mark it solved using the Tread Tools dropdown
Regards
MD
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'