Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default .find with merged cell not working

Set ck = Range("A1:A10").Find("cat")
ck="cat" if cells not merged
but
ck is nothing when cell a2="cat" and cells a2,b2,c2 are merged

Any way of serching merged cells within a range for a text string


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default .find with merged cell not working

I confirm that the Find method does not find cells that are merged when the
merge area exceeds the search range. In the below code, the first option
(Option 1) does not work as you have pointed out. To use the Find method, you
need to include the merge area of merged cells within the search range.
Alternatively, you can use a loop but it is usually less efficient.

'Assumed is that cells A2:C2 are merged as per your example
Sub Find()
Dim ck As Range

Set ck = Range("A1:A10").Find("cat")
If Not ck Is Nothing Then MsgBox ck.Address & " Option 1"

Set ck = Range("A1, A2:C2, A3:A10").Find("cat")
If Not ck Is Nothing Then MsgBox ck.Address & " Option 2"

Set ck = Range("A1: C10").Find("cat")
If Not ck Is Nothing Then MsgBox ck.Address & " Option 3"

For Each ck In Range("A1:C10").Cells
If LCase(ck) = "cat" Then
MsgBox ck.Address & " Option 4"
Exit For
End If
Next

End Sub

Regards,
Greg

"Sunil Patel" wrote:

Set ck = Range("A1:A10").Find("cat")
ck="cat" if cells not merged
but
ck is nothing when cell a2="cat" and cells a2,b2,c2 are merged

Any way of serching merged cells within a range for a text string



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default .find with merged cell not working

Correction to my post. I had intended to demonstrate that when you use a loop
it's not necessary to include entire merged ranges within the loops search
range. Only the active cell is necessary. The fourth option should have been:
For Each ck In Range("A1:A10").Cells 'Instead of A1:C10
If LCase(ck) = "cat" Then
MsgBox ck.Address & " 4"
Exit For
End If
Next

"Greg Wilson" wrote:

I confirm that the Find method does not find cells that are merged when the
merge area exceeds the search range. In the below code, the first option
(Option 1) does not work as you have pointed out. To use the Find method, you
need to include the merge area of merged cells within the search range.
Alternatively, you can use a loop but it is usually less efficient.

'Assumed is that cells A2:C2 are merged as per your example
Sub Find()
Dim ck As Range

Set ck = Range("A1:A10").Find("cat")
If Not ck Is Nothing Then MsgBox ck.Address & " Option 1"

Set ck = Range("A1, A2:C2, A3:A10").Find("cat")
If Not ck Is Nothing Then MsgBox ck.Address & " Option 2"

Set ck = Range("A1: C10").Find("cat")
If Not ck Is Nothing Then MsgBox ck.Address & " Option 3"

For Each ck In Range("A1:C10").Cells
If LCase(ck) = "cat" Then
MsgBox ck.Address & " Option 4"
Exit For
End If
Next

End Sub

Regards,
Greg


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default .find with merged cell not working

I can't confirm that. In xl97, this worked fine for me (cells A2:C2
merged)

Sub ABCD()
Set ck = Range("A1:A10").Find("cat")
MsgBox ck.Value & vbLf & ck.Address _
& vbLf & ck.MergeArea.Address

End Sub

Maybe it is one of the other settings of Find that is causing the problem.

--
Regards,
Tom Ogilvy

"Greg Wilson" wrote in message
...
I confirm that the Find method does not find cells that are merged when

the
merge area exceeds the search range. In the below code, the first option
(Option 1) does not work as you have pointed out. To use the Find method,

you
need to include the merge area of merged cells within the search range.
Alternatively, you can use a loop but it is usually less efficient.

'Assumed is that cells A2:C2 are merged as per your example
Sub Find()
Dim ck As Range

Set ck = Range("A1:A10").Find("cat")
If Not ck Is Nothing Then MsgBox ck.Address & " Option 1"

Set ck = Range("A1, A2:C2, A3:A10").Find("cat")
If Not ck Is Nothing Then MsgBox ck.Address & " Option 2"

Set ck = Range("A1: C10").Find("cat")
If Not ck Is Nothing Then MsgBox ck.Address & " Option 3"

For Each ck In Range("A1:C10").Cells
If LCase(ck) = "cat" Then
MsgBox ck.Address & " Option 4"
Exit For
End If
Next

End Sub

Regards,
Greg

"Sunil Patel" wrote:

Set ck = Range("A1:A10").Find("cat")
ck="cat" if cells not merged
but
ck is nothing when cell a2="cat" and cells a2,b2,c2 are merged

Any way of serching merged cells within a range for a text string





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default .find with merged cell not working

I think the problem occurs in xl2k+ (not xl97). (I don't have xl97 anymore, but
that's the way I remember it.)

Saved from an earlier post:

Put test in d7, e5, f7
merge E5:E9

Ctrl-F
and Find test

Hit repeat Find a few times and watch the pattern of found cells.

If you're using xl2002+, hit Find All.

Works that way in code, too.



Tom Ogilvy wrote:

I can't confirm that. In xl97, this worked fine for me (cells A2:C2
merged)

Sub ABCD()
Set ck = Range("A1:A10").Find("cat")
MsgBox ck.Value & vbLf & ck.Address _
& vbLf & ck.MergeArea.Address

End Sub

Maybe it is one of the other settings of Find that is causing the problem.

--
Regards,
Tom Ogilvy

"Greg Wilson" wrote in message
...
I confirm that the Find method does not find cells that are merged when

the
merge area exceeds the search range. In the below code, the first option
(Option 1) does not work as you have pointed out. To use the Find method,

you
need to include the merge area of merged cells within the search range.
Alternatively, you can use a loop but it is usually less efficient.

'Assumed is that cells A2:C2 are merged as per your example
Sub Find()
Dim ck As Range

Set ck = Range("A1:A10").Find("cat")
If Not ck Is Nothing Then MsgBox ck.Address & " Option 1"

Set ck = Range("A1, A2:C2, A3:A10").Find("cat")
If Not ck Is Nothing Then MsgBox ck.Address & " Option 2"

Set ck = Range("A1: C10").Find("cat")
If Not ck Is Nothing Then MsgBox ck.Address & " Option 3"

For Each ck In Range("A1:C10").Cells
If LCase(ck) = "cat" Then
MsgBox ck.Address & " Option 4"
Exit For
End If
Next

End Sub

Regards,
Greg

"Sunil Patel" wrote:

Set ck = Range("A1:A10").Find("cat")
ck="cat" if cells not merged
but
ck is nothing when cell a2="cat" and cells a2,b2,c2 are merged

Any way of serching merged cells within a range for a text string




--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default .find with merged cell not working

In xl2000, you are correct that the code I posted does not work. Manually,
If i have a single cell selected and it is not one of d7, e5, f7, then it
finds the merged cell first, then doesn't find it using findnext many times.

--
regards,
Tom Ogilvy

"Dave Peterson" wrote in message
...
I think the problem occurs in xl2k+ (not xl97). (I don't have xl97

anymore, but
that's the way I remember it.)

Saved from an earlier post:

Put test in d7, e5, f7
merge E5:E9

Ctrl-F
and Find test

Hit repeat Find a few times and watch the pattern of found cells.

If you're using xl2002+, hit Find All.

Works that way in code, too.



Tom Ogilvy wrote:

I can't confirm that. In xl97, this worked fine for me (cells A2:C2
merged)

Sub ABCD()
Set ck = Range("A1:A10").Find("cat")
MsgBox ck.Value & vbLf & ck.Address _
& vbLf & ck.MergeArea.Address

End Sub

Maybe it is one of the other settings of Find that is causing the

problem.

--
Regards,
Tom Ogilvy

"Greg Wilson" wrote in message
...
I confirm that the Find method does not find cells that are merged

when
the
merge area exceeds the search range. In the below code, the first

option
(Option 1) does not work as you have pointed out. To use the Find

method,
you
need to include the merge area of merged cells within the search

range.
Alternatively, you can use a loop but it is usually less efficient.

'Assumed is that cells A2:C2 are merged as per your example
Sub Find()
Dim ck As Range

Set ck = Range("A1:A10").Find("cat")
If Not ck Is Nothing Then MsgBox ck.Address & " Option 1"

Set ck = Range("A1, A2:C2, A3:A10").Find("cat")
If Not ck Is Nothing Then MsgBox ck.Address & " Option 2"

Set ck = Range("A1: C10").Find("cat")
If Not ck Is Nothing Then MsgBox ck.Address & " Option 3"

For Each ck In Range("A1:C10").Cells
If LCase(ck) = "cat" Then
MsgBox ck.Address & " Option 4"
Exit For
End If
Next

End Sub

Regards,
Greg

"Sunil Patel" wrote:

Set ck = Range("A1:A10").Find("cat")
ck="cat" if cells not merged
but
ck is nothing when cell a2="cat" and cells a2,b2,c2 are merged

Any way of serching merged cells within a range for a text string




--

Dave Peterson



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Form command not working on worksheet with merged cells JohnH Excel Discussion (Misc queries) 0 May 17th 10 01:28 PM
Autofit Merged cell Code is changing the format of my merged cells JB Excel Discussion (Misc queries) 0 August 20th 07 02:12 PM
How to find non-blank cell values "hidden" under merged regions? david.karr Excel Discussion (Misc queries) 7 April 7th 07 11:35 PM
how do i link merged cells to a merged cell in another worksheet. ibbm Excel Worksheet Functions 3 April 27th 06 11:40 PM
Copy/Paste Merged Cells via Macro is not working Peter Bassett Excel Programming 0 January 27th 05 07:24 PM


All times are GMT +1. The time now is 02:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"