View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Code for multiple select of cells

How about using DataValidation to handle input data type and going
with...

Private Sub Worksheet_Change(ByVal Target As Range)
If Target = Range("F1") Then FindMyVal Target.Value
End Sub

Sub FindMyVal(ValToFind&)
Dim n&, k&, sz$

n = WorksheetFunction.CountIf(ActiveSheet.UsedRange, ValToFind)
If n = 0 Then Exit Sub Else ReDim vArray(1 To n)

' Application.EnableEvents = False
For n = LBound(vArray) To UBound(vArray)
With ActiveSheet.UsedRange
For k = 1 To .Cells.Count
If .Cells(k) = ValToFind _
And InStr(sz, .Cells(k).Address) = 0 Then
sz = sz & "," & .Cells(k).Address: Exit For
End If
Next 'k
End With 'ActiveSheet.UsedRange
Next 'n
Range(Replace(Mid(sz, 2), ",", ", ")).Select
End If 'n 0
' Application.EnableEvents = True
End Sub

...where FindMyVal resides in a standard module. I'm not sure why you
toggle EnableEvents unless there's executable code in _SelectionChange.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion