Answer the question
In order to leave comments, you need to log in
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
Answer the question
In order to leave comments, you need to log in
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.
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 questionAsk a Question
731 491 924 answers to any question