View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Getting value from a TextBox to a vbs script???

How about this

Sub SearchForName()
Dim FoundCell As Range
Dim FoundFirst As Range
Dim CellWithName As String
Dim sFirst As String

With Worksheets("sheet1")
CellWithName = .TextBox1.Text
If Trim(CellWithName) = "" Then
MsgBox "Please type something"
Exit Sub
End If

With .Range("a2", .Cells(.Rows.Count, "A").End(xlUp))
Set FoundCell = .Cells.Find(What:=CellWithName, _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)

If Not FoundCell Is Nothing Then
Set FoundFirst = FoundCell
Set FoundCell = .FindNext(FoundCell)
If FoundCell Is Nothing Then FoundCell = FoundFirst
End If

End With

If FoundCell Is Nothing Then
MsgBox "not there"
Else
Application.Goto reference:=FoundCell, Scroll:=True
End If
End With

End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"kandinsky " wrote in message
...
Absolutely b-e-a utiful!

Thanx a lot mate. Just make the whole feel of the worksheet that more
intuitive, than having people typing search criterias into cells...

Now, your next assignment, should you choose to accept it...

Can you make it do the search again, from the result position (Find
Next)?

(I'll try and figure it out myself, but that will take a couple of
years, he he. I used to do a lot of Jscripting and a little Java, but
this vba is very confusing to me...)



---
Message posted from http://www.ExcelForum.com/