select particular cells

  • Thread starter Thread starter nikolaosk
  • Start date Start date
N

nikolaosk

hi there folks!!!!!


i have this problem. i have an excel workshhet and in column E i have
the word "JOHN" appearing in 11 cells of this column.

"JOHN" appears in E11, E56, E34 etc.

i want the user to select only those cells that contain the
word"JOHN". he does that by pressing ctrl button plus he clicks with
the mouse on the particular cells

i want to write a macro that i can check that the user has clicked on
those cells containing the word "JOHN" and no other cells and that the
cells are currently selected(means that the user has selected the right
cells and then leave them selected)

thanks alot
 
Nikoloas,

try something like this, to check the value of every cell
in teh curretnly selected region:

Sub IsItJohn()

dim NotJohn as Boolean
Dim Cl as Range
NotJohn = False

For Each cl in Selection.Cells
If Ucase(cl.value) <> "JOHN" Then
NotJohn = True
End If
Next cl

If NotJohn = True then
... code when there are other values in the selection
ELSE
... code for no other values in selection
End if

End Sub
 
Back
Top