2017-09-25 17 views
1

誰かが私のExcelの問題で私を助けることができますか? 私はテキストでいっぱいのセルを持っています。このテキストの一部の単語は太字で印刷されています。これらの単語はキーワードであり、キーワードの識別のために行内の別のセルに追加する必要があります。 例:細胞内Excelエクステンション太字テキスト内の単語

テキスト:

私はルート情報

出力用グーグルマップのを使用したい:

グーグル。地図;ルート;

ありがとうございます!

答えて

3

このUDFを使用して同じ結果を生成することもできます。以下のコードをモジュールに入力してください。

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 

新しく作成された関数を使用して、任意のセルから太字の値を返すことができます。

enter image description here

+0

ありがとうございます。魅力のようにも動作します:-) –

+0

あなたは大歓迎です:) –

3

hereからこのコード派生この

Option Explicit 

Sub Demo() 

    Dim ws As Worksheet 
    Dim str As String, strBold As String 
    Dim isBold As Boolean 
    Dim cel As Range 
    Dim lastRow As Long, i As Long 

    Set ws = ThisWorkbook.Sheets("Sheet1") 'change Sheet1 to your data sheet 
    isBold = False 

    With ws 
     lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row 'last row with data in Column A 
     For Each cel In .Range("A1:A" & lastRow).Cells  'loop through each cell in Column A 
      strBold = "" 
      For i = 1 To Len(cel.Value) 
       If cel.Characters(Start:=i, Length:=1).Font.Bold = True Then 'check if character is bold 
        isBold = True 
        str = Mid(cel.Value, i, 1) 
        If cel.Characters(Start:=i, Length:=1).Text = " " Then 'check for space 
         strBold = strBold & "; " 
         isBold = False 
        Else 
         strBold = strBold & str 
        End If 

       Else 
        If isBold Then 
         strBold = strBold & "; " 
         isBold = False 
        End If 
       End If 
      Next 
      cel.Offset(0, 1) = strBold 
     Next 
    End With 
End Sub 

enter image description here

を試してみてください。

+0

@JensEger - 大胆なスペースを処理するコードが更新されました。 – Mrig

+0

@NikolaosPolygenis - 上記のコードを実行しようとしましたか? – Mrig

+0

はい、うまく動作します(.Font.Bold = True)。以前のFont.FontStyle = "Bold"では、cel.Offset(0、1)にテキストは出力されません。 –

関連する問題