誰能幫我解決我的 Excel 問題?我有一個帶有文本和換行符的單元格。我需要將 bol 文本提取到行中的另一個單元格。例子:
pc 筆記本
谷歌 - 主頁
一些話
android
一些話
我使用代碼
Public Function findAllBold(ByVal rngText As Range) As String
Dim theCell As Range
Set theCell = rngText.Cells(1, 1)
For i = 1 To Len(theCell.Value)
If theCell.Characters(i, 1).Font.Bold = True Then
If theCell.Characters(i 1, 1).Text = " " Then
theChar = theCell.Characters(i, 1).Text & ", "
Else
theChar = theCell.Characters(i, 1).Text
End If
Results = Results & theChar
End If
Next i
findAllBold = Results
End Function
但我的結果是“谷歌,-,homeandroid”。最后的話粘在一起。我需要他們分開請幫幫我!
uj5u.com熱心網友回復:
這是我對您的問題的兩分錢,假設:
- 輸入中的每一行都是粗體或非粗體;
- 您希望在串聯結果中找到整行作為單個輸出。
帶有可選分隔符的函式(默認為“,”):
Function FindAllBold(rngText As Range, Optional Delimiter As String = ", ") As String
With CreateObject("vbscript.regexp")
.Global = True: .Pattern = "^. ": .MultiLine = True
For Each m In .Execute(rngText)
If rngText.Characters(m.FirstIndex 1, 1).Font.Bold = True Then
If FindAllBold = "" Then
FindAllBold = m
Else
FindAllBold = FindAllBold & Delimiter & m
End If
End If
Next
End With
End Function
通過呼叫,例如:=FindAllBold(A1, CHAR(10))

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/503717.html
上一篇:將作業表傳遞給函式以自動調整列
