Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Match a cell in a range to a value from another sheet and select r

I have 2 worksheets A & B. I have a variable cell in sheet A which I change
from 1 - 26. I have a permanent range in a column on sheet B of 1 - 26. I
need a macro that will select the row in sheet B that matches the variable in
Sheet A. If I type 5 in Sheet A, the ROW with 5 on sheet B is selected.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default Match a cell in a range to a value from another sheet and selectr

Hi Johno

If you set up a worksheet change event in the sheet tab module should
do the trick.
This assumes your Sheet B is called Sheet2 and the cell to change is
in A1 of Sheet1.

You can modify to suit. Good Luck

Marcus



Private Sub Worksheet_Change(ByVal Target As Range)
Dim LastRw As Integer
Dim rngB As Range, rngA As Range

LastRw = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row
Set rngA = Range("A1")
Set rngB = Sheets("Sheet2").Range("A2:A" & LastRw)

If Target.Address = "$A$1" Then

For Each cellB In rngB
Found = False
For Each cellA In rngA
If cellB.Value = cellA.Value Then
Found = True
Sheets("Sheet2").Activate
cellB.EntireRow.Select
End If
Next

Next
End If

End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Match a cell in a range to a value from another sheet and select r



"Johno" wrote:

I have 2 worksheets A & B. I have a variable cell in sheet A which I change
from 1 - 26. I have a permanent range in a column on sheet B of 1 - 26. I
need a macro that will select the row in sheet B that matches the variable in
Sheet A. If I type 5 in Sheet A, the ROW with 5 on sheet B is selected.


Thanks Guys for your help. I ended up doing this and it worked a treat:

Dim rngB As Range, rngA As Range
Set rngA = Range("A1")
Set rngB = Sheets("Sheet2").Range("A1:A26")
For Each cellB In rngB
Found = False
For Each cellA In rngA
If cellB.Value = cellA.Value Then
Found = True
Sheets("Sheet2").Activate
cellB.EntireRow.Select
End If
Next
Next
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
Linking sheet - Formula Match Exact or select next row and cell Lil Knight Excel Discussion (Misc queries) 0 May 15th 08 09:13 PM
Can't Select Range off sheet from inputbox Jim May Excel Discussion (Misc queries) 4 September 29th 07 08:26 PM
select a range, copy it to a new sheet Dave F Excel Discussion (Misc queries) 1 September 22nd 06 08:06 PM
Can select range of sheet ExcelMonkey Excel Programming 14 August 18th 05 02:40 PM
Select Sheet then Select Range Gee[_2_] Excel Programming 3 May 27th 04 10:10 PM


All times are GMT +1. The time now is 11:24 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"