'根据指定字符返回行号
'DataName 要搜索的数据信息
'SearchRowCount 搜索的行高
'SearchColumnCount 搜索的列宽
'RowIndex 开始行
'ColumnIndex 开始列
Public Function ReTurnRowNum(ModuleActiveWorkBook As Workbook, SheetName As String, _
DataName As String, SearchRowCount As Integer, SearchColumnCount As Integer, _
Optional RowIndex As Integer = 1, Optional ColumnIndex As Integer = 1) As Integer
ModuleActiveWorkBook.Activate
Sheets(SheetName).Activate
Dim i As Integer
Dim j As Integer
Dim a As String
i = RowIndex
j = ColumnIndex
Do Until i > SearchRowCount
For j = ColumnIndex To SearchColumnCount
If Cells(i, j).Value = DataName Then '更精准可以用Instr,多个条件,或者 用正则表达式
If Cells(i, j).MergeCells = True Then
ReTurnRowNum = i
Exit Do
Exit For
Exit Do
Else: ReTurnRowNum = 0
End If
' ElseIf Cells(i, j).Value = DataName And InStr(1, Cells(i, j).Value, "订单号", 0) = 0 And InStr(1, Cells(i, j).Value, "交货日期", 0) = 0 Then
' ReTurnRowNum = i
' Exit Do
' Exit For
' Exit Do
Else: ReTurnRowNum = 0
End If
Next
i = i + 1
Loop
End Function
参考;https://blog.csdn.net/bmjhappy/article/details/80512917
正则表达式:^[\s\S]