A
A
asdz2015-03-16 01:06:25
Macros
asdz, 2015-03-16 01:06:25

Excel VBA why not search in merged cells?

Hello!
Faced the problem that Excel 2013 does not search for text programmatically from VBA and C# in merged cells. Manual search works fine. I write down a macro of search in contents, search finds cells. After recording the macro, I try to run it in debug mode and see that the single cell is found, but the merged one is not.
Macro text:

Sub Макрос5()
'
' Макрос5 Макрос
'

'
    Cells.Find(What:="xxx", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
        xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
    Cells.FindNext(After:=ActiveCell).Activate
    Cells.FindNext(After:=ActiveCell).Activate
End Sub

sheet contents:
39e95580a6434ca78fc5ce1ee982b0e1.png
Link to macro file ge.tt/849QWKC2/v/0?c

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Saboteur, 2015-03-16
@asdz

Because VBA works crookedly with merge cells, and the official site of Excel does not recommend using merged cells if you are developing something complex in VBA, because this violates both sorting and cell looping.
Of course, you can come up with crutches by iterating over cells in a loop, but most of the ready-made functions for processing columns and rows will not work.

D
DrAkosh365, 2020-07-21
@DrAkosh365

It is necessary to search in columns, that is, in columns.
ub Preire_to_record()
' Macro Preire to record
Dim nomdoma As Object
Dim a As Object
Dim b As Object
Dim ws As Worksheet
Dim c As Object
Dim d As Object
Dim e As Integer
Set a = Workbooks(1).Worksheets(1). Range("E18")
Set b = Workbooks(1).Worksheets(1).Range("E19")
If a.Value = 12 Then
Set ws = dom12
ElseIf a.Value = 13 Then
Set ws = dom13
ElseIf a. Value = 16 Then
Set ws = dom16
ElseIf a.Value = 18 Then
Set ws = dom18
ElseIf a.Value = 20 Then
Set ws = dom20
Else
MsgBox "No house with current number!"
Exit Sub
End If
e = ws.index 'does not equal to worksheet index'
If ws.index = dom16.index And b >= 49 Then 'MsgBox dom16.Type Refer to the type of the named worksheet and specify in the if
MsgBox "In home " & a.Value & " with number "& _ b
& " apartment does not exist. There is 48 sq. !

lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)

ThisWorkbook.Worksheets(e).Select
Range(nomdoma.Address).Offset(rowOffset:=0, columnOffset:= -7).Select
End Sub
Use Range("A:A").Find function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question