How to find cell with specific format?

  • Thread starter Thread starter NOPIK
  • Start date Start date
N

NOPIK

I want to speed up my select procedure. Is there any VBA method or
Excel function to find specified format (MergedCells in my case) in
Cells range?
 
I found this in the VBA help menu.

Set ma = Range("a3").MergeArea
If Range("a3").MergeCells Then
ma.Cells(1, 1).Value = "42"
End If


Letting VBA search a range is always faster than indexing rows and columns.
I usually do this

Set Myrange = Range("A1:Z:50)
For each MyCell in Myrange

Next MyCell
 
If you're using xl2002+, the Edit|Find has been enhanced to look for
formating--including merged cells (in my little test).

I'm not sure what you're doing, but this may help (for xl2k and below):

How about a little macro:

Option Explicit
Sub testme()

Dim myCell As Range
Dim resp As Long

For Each myCell In ActiveSheet.UsedRange.Cells
If myCell.MergeCells Then
If myCell.Address = myCell.MergeArea(1).Address Then
resp = MsgBox(prompt:="found: " _
& myCell.MergeArea.Address & vbLf & _
"Continue looking", Buttons:=vbYesNo)
If resp = vbNo Then
Exit Sub
End If
End If
End If
Next myCell

End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
 
Thanks, people. At the moment I use
Reslt=.Find "Context data"
if Reslt.MergeCells then SearchSucceed
so I wanted much safer way, than relate on user affected context
(search is in deep loop and I can't sacrifice speed to use walk by
range, anyway it perfomed, if context data not found in range).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top