Find And Select Multiple Cells

YasserKhalil

Well-known Member
Joined
Jun 24, 2010
Messages
852
Hello every body

In Range("I2") I have avalue ..
I want to use vba to find this value in the range ("A1:H50") as a whole

I want the code to be in Worksheet_Change so as to when typing a new value in I2 the cells that match this value to be selected
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
In Range("I2") I have avalue ..
I want to use <acronym title="visual basic for applications">vba</acronym> to find this value in the range ("A1:H50") as a whole

I want the code to be in Worksheet_Change so as to when typing a new value in I2 the cells that match this value to be selected

I think my request is clear .. If it is difficult tell me to stop posting ?
 
Upvote 0
Hi YasserKhalil,

Do you really need to SELECT the cells, or would highlighting them be okay?

If selection is what you must have what will you do with the SELECTION?

Howard
 
Upvote 0
Hi YasserKhalil,

Give this a try.

Regards,
Howard


Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
'/by[B] Claus MS Public Prog[/B].

If Intersect(Target, Range("I2")) Is Nothing Then Exit Sub
Application.EnableEvents = False

If IsNumeric(Target.Value) = False Then
   Range("I3").Select
   MsgBox "Must be number!"
   Range("I2").ClearContents
   Application.EnableEvents = True
   Exit Sub
End If

Dim rngBig As Range, rngC As Range
Dim aNum As Long
aNum = Range("I2")
For Each rngC In ActiveSheet.Range("A1:H50")
   If rngC.Value = aNum And rngBig Is Nothing Then
      Set rngBig = rngC
   ElseIf rngC = aNum And Not rngBig Is Nothing Then
         Set rngBig = Union(rngBig, rngC)
   End If
Next

Application.EnableEvents = True
rngBig.Select

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,532
Messages
6,172,875
Members
452,486
Latest member
standw01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top