Я кодирую поиск, который пересекает набор данных на листе Excel.В настоящее время код выполняется для точного соответствия, сопоставляя поле поиска с ячейкой.Тем не менее, я хочу, чтобы моя программа могла выполнять поиск и выдавать результаты даже в случаях поиска в ячейке (строка внутри ячейки).Например, поиск слова «собака» в ячейке с надписью «эта собака коричневого цвета» должен вернуть всю ячейку.
Я уже попробовал следующее, включив следующий фрагмент, но он не работает
searchString = dataArray(i, searchField)
If InStr(UCase("searchString"), UCase("searchField")) = 1 Then
Ниже приведен действительный код:
'Get the range values into a variable that can be looped through.
'Example usage: dataArray(1,1) [row,column]
'Simple version: ws.Range(Cells(1,1),Cells(2,2)).Value
dataArray = ws.Range(ws.Cells(dataRowStart, dataColumnStart), ws.Cells(ws.Cells(Rows.Count, dataColumnStart).End(xlUp).Row, dataColumnEnd)).Value
'Increase size of array that will hold the data to display to its max possible size for the current worksheet.
ReDim datatoShowArray(1 To UBound(dataArray, 1), 1 To UBound(dataArray, 2))
'Row increment for the final data array (datatoShowArray).
j = 1
'Loop through the rows in the data range.
For i = 1 To UBound(dataArray, 1)
'Check if the value in the row equals our search value
If (dataArray(i, searchField) = searchValue) Then
'MATCH FOUND! Now do something!
'Loop through the columns in the data range so can get their values.
For k = 1 To UBound(dataArray, 2)
'Add values to the array that will be used to put data into the Dashboard.
datatoShowArray(j, k) = dataArray(i, k)
Next k
'Increment the counter for the datatoShowArray
j = j + 1
End If