Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Search in row

Hi all,

I have data something like:
type from to
a 1000 1500
b 1501 2500
c 2501 2750

i want to search for a number and find out in which row it comes

for eg: if i type 1750 it comes in b (starting 1501 and ending 2500)

how can i acheive this using VBA?

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Search in row

Hi,
Try this which assumes data is in colums A to C and there is a header
row.
It checks if value to be matched is within limits of data and returns 0 if
not; otherwise returns the row number of match .

Sub testMatch()
MsgBox FindRow(3001)
End Sub



Function FindRow(ByVal MatchVal As Integer)
Dim Lastrow As Integer, mRow As Integer, Matchrng As Range

Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Set Matchrng = Range("b2:B" & Lastrow)

' Check if value is within limits of table
If MatchVal Application.Max(Range("C2:C" & Lastrow)) _
Or MatchVal < Application.Min(Range("B2:B" & Lastrow)) Then
MsgBox MatchVal & " is out of range"
FindRow = 0 ' Return row number of 0
Exit Function
Else
FindRow = Application.Match(MatchVal, Matchrng)+ 1
End If

End Function


HTH


"Soniya" wrote:

Hi all,

I have data something like:
type from to
a 1000 1500
b 1501 2500
c 2501 2750

i want to search for a number and find out in which row it comes

for eg: if i type 1750 it comes in b (starting 1501 and ending 2500)

how can i acheive this using VBA?

Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Search in row

thanks for your reply..

it works when the number is small and returns an error when the number
is big

if the number is in 1000 etc it worked. but when i used 400000 etc it
says overflow?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Search in row

Change Function FindRow(ByVal MatchVal As Integer) to

Function FindRow(ByVal MatchVal As Long)



"Soniya" wrote:

thanks for your reply..

it works when the number is small and returns an error when the number
is big

if the number is in 1000 etc it worked. but when i used 400000 etc it
says overflow?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Search in row

Sub findunm()
MsgBox Cells(Application.Match(1700, Columns(4)), "c")
'or if 1700 in b2
MsgBox Cells(Application.Match(Cells(2, 2), Columns(4)), "c")
End Sub

or a built in function
=INDIRECT("c"&MATCH(B2,D3:D23)+2)

--
Don Guillett
SalesAid Software

"Soniya" wrote in message
ups.com...
Hi all,

I have data something like:
type from to
a 1000 1500
b 1501 2500
c 2501 2750

i want to search for a number and find out in which row it comes

for eg: if i type 1750 it comes in b (starting 1501 and ending 2500)

how can i acheive this using VBA?

Thanks



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
Two search category & two search terms avk Excel Discussion (Misc queries) 1 June 2nd 10 01:25 PM
file search or search files Richad Excel Discussion (Misc queries) 0 October 22nd 09 07:56 PM
Functions (search within search result) reply to this please Nick Excel Worksheet Functions 1 February 17th 09 03:57 AM
How do I search excel spreadsheets using multiple search criteria. Kasper Excel Worksheet Functions 4 December 15th 05 12:26 AM
Create a search Field within a worksheet to search command buttons Ed P[_2_] Excel Programming 1 December 14th 04 08:04 PM


All times are GMT +1. The time now is 04:42 PM.

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"