Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Using a Macro to find a value in a range and activate it

Hi,
I'm trying to write a portion of a macro that will
take the value contained in a specified cell, and look for
another cell in a specified range that has the same
value. I've been working on this for several hours but
haven't had any luck....any suggestions?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Using a Macro to find a value in a range and activate it

Hi Travis,

Here's one way to do it:

Public Sub FindMatch(rvFindWhat As Variant, _
rrngTarget As Range, Optional rbMatchCase As _
Boolean = True)
On Error Resume Next
rrngTarget.Find(What:=rvFindWhat, _
MatchCase:=rbMatchCase).Select
On Error GoTo 0
End Sub

Public Sub Test()
FindMatch Range("A1").Value, Range("D1:G10")
End Sub

Basically, you are using the built-in Find tool to find/select the range, if
it exists. If no match is found, nothing happens.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Travis wrote:
Hi,
I'm trying to write a portion of a macro that will
take the value contained in a specified cell, and look for
another cell in a specified range that has the same
value. I've been working on this for several hours but
haven't had any luck....any suggestions?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using a Macro to find a value in a range and activate it

I may be misunderstanding, but how about:


Code
-------------------
Sub test()

Dim r As Range
Dim strFind As String

strFind = Range("B13").Value

For Each r In Range("E13:F22")
If r.Value = strFind Then
r.Select
Exit For
End If
Next

End Su
-------------------



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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Using a Macro to find a value in a range and activate it

I think I've left a couple important bits out....the cell
that contains the primary search value is on a different
sheet ("Add-Remove") than the the sheet containing the
range I want to find it in ("Lists"). In addition, once I
find the cell in the range that contains the correct value
(which will be in column a), I want to delete the contents
of the cells in colums B,C,D,E and V in the same row as
the 'found' cell



-----Original Message-----
Hi Travis,

Here's one way to do it:

Public Sub FindMatch(rvFindWhat As Variant, _
rrngTarget As Range, Optional rbMatchCase As _
Boolean = True)
On Error Resume Next
rrngTarget.Find(What:=rvFindWhat, _
MatchCase:=rbMatchCase).Select
On Error GoTo 0
End Sub

Public Sub Test()
FindMatch Range("A1").Value, Range("D1:G10")
End Sub

Basically, you are using the built-in Find tool to

find/select the range, if
it exists. If no match is found, nothing happens.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address

unmonitored]


Travis wrote:
Hi,
I'm trying to write a portion of a macro that will
take the value contained in a specified cell, and look

for
another cell in a specified range that has the same
value. I've been working on this for several hours but
haven't had any luck....any suggestions?


.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Using a Macro to find a value in a range and activate it

Hi Travis,

travis wrote:
I think I've left a couple important bits out....the cell
that contains the primary search value is on a different
sheet ("Add-Remove") than the the sheet containing the
range I want to find it in ("Lists"). In addition, once I
find the cell in the range that contains the correct value
(which will be in column a), I want to delete the contents
of the cells in colums B,C,D,E and V in the same row as
the 'found' cell


Yes, those are important things to know. <g

Try this one instead:

Public Sub FindMatch(rvFindWhat As Variant, _
rrngTarget As Range, Optional rbMatchCase As _
Boolean = True)
Dim rng As Range

On Error Resume Next
Set rng = rrngTarget.Find(What:=rvFindWhat, _
MatchCase:=rbMatchCase)
On Error GoTo 0

If Not rng Is Nothing Then
With rng.Parent
.Cells(rng.Row, 2).ClearContents
.Cells(rng.Row, 3).ClearContents
.Cells(rng.Row, 4).ClearContents
.Cells(rng.Row, 5).ClearContents
.Cells(rng.Row, 22).ClearContents
End With
End If
End Sub

Public Sub Test()
With Sheets("List")
FindMatch Sheets("Add-Remove").Range("A1"). _
Value, Application.Intersect(.Range("A:A") _
, .UsedRange)
End With
End Sub


You'll notice that I don't select or activate anything. This will increase
performance and leave the user's current selection alone.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

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
Macro to find value and then copy associated range hnyb1 Excel Discussion (Misc queries) 1 December 31st 09 04:09 PM
Activate cell at end of range G Setting up and Configuration of Excel 2 November 22nd 05 04:10 PM
use of range and activate crichardson Excel Programming 4 March 2nd 04 03:29 PM
range.activate Rune_Daub[_16_] Excel Programming 1 February 12th 04 06:55 PM
Macro to find the 6th occurrence and move range cynthia Excel Programming 0 January 22nd 04 03:48 AM


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