B
bourgui
Hi All,
I have this routine which searches for the next used cell, using the
'Find' method.
My problem is when searching by column, merged cells are skipped,
depending on the the merged range:
If I search by row and the merge area spans over sevral rows, the
merged cell is skipped. If the merged area is contained within a
single row, the merged cell is NOT skipped.
Similarly for a column, if the merged area is over several column,
'Find' skips over the cell, otherwise, the merged area is not skipped.
For example, type 'Test' in cell B2, then merge B2-D2 and call the
'Find' function on the second column, like:
Set fCell = Cells.Find(What:="*", After:=ActiveCell,
LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False)
(assuming you have selected B1)
The funny thing is, it works fine when I search manually, using Ctrl
+F. But even if I record the macro then run it on the same document,
it skips merged cells when the function is called from VBA!!!
I have tried setting the FindFormat to look for merged cells
(application.FindFormat.MergeCells = true, and switch the SearchFormat
parameter to true), but that didn't help.
I'm at a loss here, and this is getting quite urgent. Any help very
much appreciated!
I have this routine which searches for the next used cell, using the
'Find' method.
My problem is when searching by column, merged cells are skipped,
depending on the the merged range:
If I search by row and the merge area spans over sevral rows, the
merged cell is skipped. If the merged area is contained within a
single row, the merged cell is NOT skipped.
Similarly for a column, if the merged area is over several column,
'Find' skips over the cell, otherwise, the merged area is not skipped.
For example, type 'Test' in cell B2, then merge B2-D2 and call the
'Find' function on the second column, like:
Set fCell = Cells.Find(What:="*", After:=ActiveCell,
LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False)
(assuming you have selected B1)
The funny thing is, it works fine when I search manually, using Ctrl
+F. But even if I record the macro then run it on the same document,
it skips merged cells when the function is called from VBA!!!
I have tried setting the FindFormat to look for merged cells
(application.FindFormat.MergeCells = true, and switch the SearchFormat
parameter to true), but that didn't help.
I'm at a loss here, and this is getting quite urgent. Any help very
much appreciated!