Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

displaying the cursor in a specific cell using a cmdButton 1

Status
Not open for further replies.

Conner

Technical User
Nov 29, 2000
44
0
0
US
I have managed to develop the following elementary code for a cmdbutton on an excel spreadsheet...

Private Sub CommandButton1_Click( )
'Open an input box
Dim DateYear as String
DateYear=InputBox ("Enter a Year")
If DateYear="" Then exit sub
else......'here's where I get lost.

End Sub

If a year is entered in the textbos, then I want the cursor to move to the cell that has that date, and that part of the spreadsheet appear in the windows area. I have thousands of dates and don't want to keep scrolling through a massive spreadsheet looking for a particular date...It's been suggested I use VLOOKUP, but I don't know how to write the code...What would follow the Else. Column A contains my dates, and Column B the text....should be very simple, but I can't get it to work...


 
Here is some code to get you on your way.
Assumptions:
[ul]
[li]The worksheet name is "Sheet1"[/li]
[li]The Range where the years lie is the entire "A" column[/li]
[/ul]

[tt]
Private Sub CommandButton1_Click()
Dim DateYear As String
Dim fRange As Range

DateYear = InputBox("Enter a Year")
If DateYear = "" Then
Exit Sub
Else
With Worksheets("Sheet1").Range("A:A")
Set fRange = .Find(DateYear)
fRange.Select
End With
End If
End Sub
[/tt]

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top