Board logo

標題: EXCEL FIND WORDS In ONE CELL [打印本頁]

作者: lvanb    時間: 2023-10-11 13:15     標題: EXCEL FIND WORDS In ONE CELL

如何在EXCEL找到某CELL 含有二個字
但這二字不是相連的

例如: WORK BUS
任何CELL 祗要有這二字, 即使非相連, 都可找到

GOOGLE過, 但並非我相要的

謝謝
作者: javacomhk    時間: 2023-10-11 17:49

Regular expression match this
.*?(WORK).*?(BUS).*?
作者: bongbong3481    時間: 2023-10-11 19:04

留名學野
作者: bongbong3481    時間: 2023-10-11 19:10

如何在EXCEL找到某CELL 含有二個字
但這二字不是相連的

例如: WORK BUS
任何CELL 祗要有這二字, 即使非相 ...
lvanb 發表於 2023-10-11 13:15



我暫時想到用2個countinif (cell ,"*keyword*")相加,
結果是2應該就有果兩個字
作者: dipsy    時間: 2023-10-12 11:29

如何在EXCEL找到某CELL 含有二個字
但這二字不是相連的

例如: WORK BUS
任何CELL 祗要有這二字, 即使非相 ...
lvanb 發表於 2023-10-11 13:15


問咗Bard
=AND(COUNTIF(A1:B1,"*WORK*")>=1,COUNTIF(A1:B1,"*BUS*")>=1)
如果是 true 就係有晒 WORK 同BUS
作者: lvanb    時間: 2024-1-26 21:29

謝謝大家
作者: s20012797    時間: 2024-1-27 13:11

  1. def find_unconnected_words():
  2.     word1 = input("Enter the first word:")
  3.     word2 = input("Enter the second word:")
  4.     found_cells = []
  5.     for row in range(1, sheet.max_row + 1):
  6.         for column in range(1, sheet.max_column + 1):
  7.             cell_value = sheet.cell(row=row, column=column).value
  8.             if word1 in cell_value and word2 in cell_value:
  9.                 found_cells.append((row, column))
  10.     for cell in found_cells:
  11.         print(f"Cell at ({cell[0]}, {cell[1]})")
  12. find_unconnected_words()
複製代碼
幾行code搞掂

作者: lvanb    時間: 2024-2-17 10:43

thank you
作者: jimking332    時間: 2024-2-19 10:51

幾行code搞掂
s20012797 發表於 2024-1-27 13:11


呢D唔係Excel VBA, 請問係咩code?
作者: bongbong3481    時間: 2024-2-19 16:29

回覆 9# jimking332


    應該是python
作者: s20012797    時間: 2024-2-19 17:29

回覆  jimking332


    應該是python
bongbong3481 發表於 2024/2/19 16:29


用VBA寫煩好多Lo
  1. Sub FindUnconnectedWords()
  2.     Dim Word1 As String
  3.     Dim Word2 As String
  4.     Dim FoundCells As Collection
  5.     Dim Row As Long
  6.     Dim Column As Long
  7.     Dim CellValue As String
  8.     Dim Cell As Range
  9.     Dim FoundCell As Range
  10.     Word1 = InputBox("Enter the first word:")
  11.     Word2 = InputBox("Enter the second word:")
  12.     Set FoundCells = New Collection
  13.     For Row = 1 To ThisWorkbook.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
  14.         For Column = 1 To ThisWorkbook.Sheets(1).Cells(1, Columns.Count).End(xlToLeft).Column
  15.             CellValue = ThisWorkbook.Sheets(1).Cells(Row, Column).Value
  16.             If InStr(1, CellValue, Word1) > 0 And InStr(1, CellValue, Word2) > 0 Then
  17.                 FoundCells.Add ThisWorkbook.Sheets(1).Cells(Row, Column)
  18.             End If
  19.         Next Column
  20.     Next Row
  21.     For Each FoundCell In FoundCells
  22.         Debug.Print "Cell at (" & FoundCell.Row & ", " & FoundCell.Column & ")"
  23.     Next FoundCell
  24. End Sub
複製代碼

作者: bongbong3481    時間: 2024-2-19 17:53

回覆 11# s20012797


    唔用DIM , 應該可以刪幾行, 另外, 樓上有D POST 用公式整都好似得





歡迎光臨 電腦領域 HKEPC Hardware (https://h2.hkepc.com/forum/) Powered by Discuz! 7.2