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

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
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,214,641
Messages
6,120,695
Members
448,979
Latest member
DET4492

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