View Single Post
  #14   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


Hi Garry and Claus,

I am using the range A1:H50 testing. All cells filled with 5.

Claus's Sub MultiSelect() code all cells selected in a blink.

Claus's Sub MultiSelect2() code all cells selected in blink & 1/2.

Garry's code Sub FindMyVal() errors out with the full range. Reduce
cells around to about 30 - 40 works okay.

Glad to have all the options. Thanks.

Howard


Claus has a better suggested approach! My use of the range defined with
a string of addresses is limited to a small number of args. In the case
of your test area being contiguous and identical values, using my
approach doesn't make sense because the entire area can be selected
with 2 keyboard strokes (Ctrl+Shift+[dn][right] arrow keys!

The revised version (also in a blink)...

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

n = WorksheetFunction.CountIf(ActiveSheet.UsedRange, ValToFind)
If n = 0 Then Exit Sub

With ActiveSheet.UsedRange
If n = .Cells.Count Then .Select: Exit Sub

For n = 1 To .Cells.Count
If .Cells(n) = ValToFind And rng Is Nothing Then
Set rng = .Cells(n)
ElseIf .Cells(n) = ValToFind And Not rng Is Nothing Then
Set rng = Union(rng, .Cells(n))
End If
Next 'n
End With 'ActiveSheet.UsedRange
rng.Select
End Sub

Thanks to Claus...

--
Garry

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