Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel
external usenet poster
 
Posts: 5
Default Macro to search number with in a series.

Dear frineds,

I have an Excel table like below,


A B C
1 Box Number Seal num. from Seal num. to

2 BOX 1 004569 004600

3 BOX2 020034 020106

4 BOX3 000237 000320

5 BOX4 001003 001130



I want to write a macro to search a Seal Number with in the series. For example,
When I input 020100, it should highlight the row 3. as well when I input 000300
It should highlight row 4.

Could anyone give me a bright idea as how to do this?
Thank you in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel
external usenet poster
 
Posts: 27,285
Default Macro to search number with in a series.

Assume you want to react with a value is entered in G2

right click on the sheet module and select view code. Paste in code like
this:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim rng As Range
If Target.Count 1 Then Exit Sub
If Target.Address = "$G$2" Then
Cells.Interior.ColorIndex = xlNone
Set rng = Range(Cells(2, 2), Cells(Rows.Count, 2).End(xlUp))
For Each cell In rng
If cell.Value <= Target And cell.Offset(0, 1).Value = Target.Value Then
cell.EntireRow.Interior.ColorIndex = 6
Exit Sub
End If
Next
End If
End Sub

Assumes you aren't using colored cells on the sheet, except for this
highlight.

--
Regards,
Tom Ogilvy


"Fernando" wrote in message
om...
Dear frineds,

I have an Excel table like below,


A B C
1 Box Number Seal num. from Seal num. to

2 BOX 1 004569 004600

3 BOX2 020034 020106

4 BOX3 000237 000320

5 BOX4 001003 001130



I want to write a macro to search a Seal Number with in the series. For

example,
When I input 020100, it should highlight the row 3. as well when I input

000300
It should highlight row 4.

Could anyone give me a bright idea as how to do this?
Thank you in advance.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Macro to search number with in a series.

Thank you very much Mr Tom Ogilvy it works perfect.

Insted of column B and C if I have the "seal series" in colum M and O
How should I alter this code?

Is it also possible to select the cell S on the highlighted row?

I really appriciate your help.



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Macro to search number with in a series.

Sorry I forgot to mention.
There can be occurrences in this nature too,

A B C
1 Box Number Seal num. from Seal num. to

2 BOX 1 004569 004600

3 BOX2 102000 103000

4 BOX3 102100 102500

5 BOX4 102200 102300



In this situation if you input 102250 to search, three rows have to be
highlighted. Row 3, 4, and 5.
And the selected cell should be at the first occurrence on the row J

After I saw your solution Mr. Tom Ogilvy , only it strikes me about
these new problems.

Sorry for the trouble.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro to search number with in a series.

You said select S, then in the next post you say something about J. The
below selects S. Change to J if that is what you want.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim rng As Range, cell as Range, bFound as Boolean
If Target.Count 1 Then Exit Sub
If Target.Address = "$G$2" Then
Cells.Interior.ColorIndex = xlNone
Set rng = Range(Cells(2, 18, Cells(Rows.Count, 18).End(xlUp))
bFound = False
For Each cell In rng
If cell.Value <= Target And cell.Offset(0, 1).Value = Target.Value Then
if not bFound then
cells(cell.row,"S").Select
bFound = True
End If
cell.EntireRow.Interior.ColorIndex = 6
End If
Next
End If
End Sub

--
Regards,
Tom Ogilvy


"Priyanga Fernando" wrote in message
...
Sorry I forgot to mention.
There can be occurrences in this nature too,

A B C
1 Box Number Seal num. from Seal num. to

2 BOX 1 004569 004600

3 BOX2 102000 103000

4 BOX3 102100 102500

5 BOX4 102200 102300



In this situation if you input 102250 to search, three rows have to be
highlighted. Row 3, 4, and 5.
And the selected cell should be at the first occurrence on the row J

After I saw your solution Mr. Tom Ogilvy , only it strikes me about
these new problems.

Sorry for the trouble.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Macro to search number with in a series.

Hello Mr Ogilvy,

It works perfect.

Now I sort of figured out
Set rng = Range(Cells(2, 18), Cells(Rows.Count, 18).End(xlUp))
By changing the values of this line you can select the cells that Seals
numbers are. I have no idea what

Cells(Rows.Count, 18).End(xlUp) and
If cell.Value <= Target And cell.Offset(0, 1).Value = Target.Value
does.

My VB knowledge is minimal. Will I trouble you, if I sak you to comment
your coding? So that I could learn something from it. At least above two
lines.

Thank you very much again.

Best regards,

Fernando

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
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
Finding next number in a series Iriemon Excel Worksheet Functions 2 May 12th 10 09:11 PM
User Selectable Series and Number of Series for Line Chart Dave in NJ Charts and Charting in Excel 2 February 23rd 09 12:18 AM
Number Search In Lottery Number Sets JAgger1 Excel Discussion (Misc queries) 25 February 11th 09 04:49 PM
How do I change a social security number to a number series? LCDawn Excel Discussion (Misc queries) 4 December 22nd 05 04:15 PM
search a series of rows for a specific formating Harris Excel Worksheet Functions 2 July 30th 05 11:46 PM


All times are GMT +1. The time now is 11:46 PM.

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

About Us

"It's about Microsoft Excel"