vba find 单元格换行的情况

发布时间 2023-11-23 16:25:54作者: 信尚

如果文本是使用Alt+Enter方法在单元格中输入的,则可以在VBA中使用以下代码:

" & Chr(10) & "

下面为样例的.Find方法。

Private Sub CommandButton1_Click()
Set RngClosedDate = Range("A1:Z10").Find(What:="Closed" & Chr(10) & "(Date)", LookAt:=xlWhole, LookIn:=xlValues)
      ' If the text that is searched for from the line above is not found then a message box is displayed and sub function is exitied
      If RngClosedDate Is Nothing Then
        MsgBox "Closed (Date) Column Header Not found.  Cannot sort or format records."
        Exit Sub
      End If
End Sub