Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
mas mas is offline
external usenet poster
 
Posts: 5
Default searching a table - fast!

Hi,

What is the best way to search a table for a specific value using VBA code
in Excel.

Code follows:

i = 0
Do While i = 0
If ActiveCell.Value = 11111 Then
ActiveCell.Offset(0, 1).Select
Do While j = 0
If ActiveCell.Value = 1 Then
ActiveCell.Offset(0, 1).Select
price = ActiveCell.Value
i = 1
j = 1
Else
ActiveCell.Offset(1, 0).Select
End If
Loop
Else
ActiveCell.Offset(1, 0).Select
End If
Loop




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default searching a table - fast!

Look at Find in VBA Help.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"mas" wrote in message
...
Hi,

What is the best way to search a table for a specific value using VBA code
in Excel.

Code follows:

i = 0
Do While i = 0
If ActiveCell.Value = 11111 Then
ActiveCell.Offset(0, 1).Select
Do While j = 0
If ActiveCell.Value = 1 Then
ActiveCell.Offset(0, 1).Select
price = ActiveCell.Value
i = 1
j = 1
Else
ActiveCell.Offset(1, 0).Select
End If
Loop
Else
ActiveCell.Offset(1, 0).Select
End If
Loop






  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default searching a table - fast!

hi
try this. it will search all sheets.
Private Sub CommandButton2_Click()
Dim sStr As String
Dim sh As Worksheet
Dim rng As Range

Sheets("yoursheet").Select
sStr = InputBox("Enter something.")
For Each sh In ThisWorkbook.Worksheets
If sStr < "" Then
Set rng = Nothing
Set rng = sh.Range("A1:IV65536").Find(What:=sStr, _
After:=sh.Range("A1"), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
End If
If Not rng Is Nothing Then
MsgBox "Found on sheet " & sh.Name & " at cell " & _
rng.Address
rng.Select
Exit Sub
End If
Next sh
If rng Is Nothing Then
MsgBox sStr & " was Not found"
End If

End Sub
-----Original Message-----
Hi,

What is the best way to search a table for a specific

value using VBA code
in Excel.

Code follows:

i = 0
Do While i = 0
If ActiveCell.Value = 11111 Then
ActiveCell.Offset(0, 1).Select
Do While j = 0
If ActiveCell.Value = 1 Then
ActiveCell.Offset(0, 1).Select
price = ActiveCell.Value
i = 1
j = 1
Else
ActiveCell.Offset(1, 0).Select
End If
Loop
Else
ActiveCell.Offset(1, 0).Select
End If
Loop




.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default searching a table - fast!

For a fixed range something like this:

Sub Macro1()

Range("D5:Z65000").Select
Selection.Find(What:="1", After:=ActiveCell, LookIn:=xlValues,
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate

ActiveCell.Offset(0, 1).Select
price = ActiveCell.Value


End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Searching from a table [email protected] Excel Worksheet Functions 4 July 6th 08 11:12 AM
Searching Data Table Rob F Excel Discussion (Misc queries) 1 January 11th 07 07:25 PM
Table Searching Joe Miller Excel Discussion (Misc queries) 10 August 8th 06 09:03 PM
searching in more than one table andyell Excel Discussion (Misc queries) 3 July 12th 06 08:51 AM
how do I set up a fast comparison table? Biologist Excel Discussion (Misc queries) 1 June 21st 05 01:24 AM


All times are GMT +1. The time now is 05:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"