メインコンテンツへスキップ

Excelのテキスト文字列から最初/最後/ n番目の単語を抽出する方法は?

ワークシートのテキスト文字列から特定の単語を抽出する必要があるという問題に悩まされたことはありますか? たとえば、最初/最後またはn番目の単語を取得するために必要な次の範囲のテキスト文字列があります。ここでは、それを解決するためのいくつかの効果的な方法について説明します。


数式を使用してテキスト文字列から姓または名を抽出します

テキスト文字列のリストから最初の単語を抽出する必要がある場合は、次の式が役立ちます。

最初の単語を抽出するには、以下の数式を空白のセルに入力し、このセルのオートフィルハンドルを必要に応じて範囲にドラッグしてください。

= IF(ISERR(FIND( ""、A2))、 ""、LEFT(A2、FIND( ""、A2)-1))

各セルから最後の単語を抽出するには、次の数式を適用してください。

= IF(ISERR(FIND( ""、A2))、 ""、RIGHT(A2、LEN(A2)-FIND( "*"、SUBSTITUTE(A2、 ""、 "*"、LEN(A2)-LEN( SUBSTITUTE(A2、 ""、 "")))))))

そして今、あなたは最初または最後の単語が各セルから抽出されているのを見るでしょう。

注意: 上記の式では、 A2 最初または最後の単語を抽出するセルを示します。

長く複雑な数式を覚えるのは難しいですか? 素晴らしいツールは、n番目の単語を抽出するのに役立ちますw数回クリックするだけです!

上記の長い数式は最初と最後の単語しか抽出できませんが、指定されたn番目の単語を抽出することはできません、XNUMX番目の単語、XNUMX番目の単語などを言います。問題を解決するための数式を理解できたとしても、数式は次のようになります。複雑すぎて覚えて適用できません。 ここでは、Kutools for Excelのセル内のn番目の単語を抽出する機能をお勧めします。これにより、n番目の単語をできるだけ簡単に抽出できます。


Kutools for Excel - 300 以上の必須ツールで Excel を強化します。 クレジット カードは必要なく、全機能を備えた 30 日間の無料トライアルをお楽しみください。 今すぐ入手

ユーザー定義関数を使用して、テキスト文字列からn番目の単語を抽出します

テキスト文字列からXNUMX番目、XNUMX番目、または任意のn番目の単語を抽出する場合は、それを処理するユーザー定義関数を作成できます。

1。 を押し続けます Alt + F11 キーを押して Microsoft Visual Basic forApplicationsウィンドウ.

2に設定します。 OK をクリックします。 インセット > モジュール、次のコードをに貼り付けます モジュール 窓。

Function FindWord(Source As String, Position As Integer)
'Update 20131202
Dim arr() As String
arr = VBA.Split(Source, " ")
xCount = UBound(arr)
If xCount < 1 Or (Position - 1) > xCount Or Position < 0 Then
    FindWord = ""
Else
    FindWord = arr(Position - 1)
End If
End Function

3。 次に、コードを保存します。この例では、文字列からXNUMX番目の単語を取得するので、この式を入力します = findword(A2,3) 空白のセルB2に挿入し、このセルのオートフィルハンドルを必要に応じて範囲にドラッグします。 スクリーンショットを参照してください:

注: 上記の式では、 A2 単語を抽出したいセル、数字 3 抽出する文字列のXNUMX番目の単語を示し、必要に応じて変更できます。


テキスト文字列から各単語を抽出し、水平方向または垂直方向にリストします

このメソッドは、Excel用のKutoolsを導入します 分割セル テキスト文字列セルから各単語を抽出し、必要に応じて抽出された単語を水平方向または垂直方向に一覧表示するユーティリティ。

Kutools for Excel - Excel に必要な 300 以上のツールが詰め込まれています。 クレジット カードは必要なく、全機能を備えた 30 日間の無料トライアルをお楽しみください。 ダウンロード中!

1。 単語を抽出するテキスト文字列セルを選択し、[ クツール > マージ&スプリット > 分割セル.

2。 [セルの分割]ダイアログボックスを開くときに、で分割タイプを指定します。 タイプ セクションで、 スペース 内のオプション 区切り文字を指定します セクションを開き、 Ok ボタン。 スクリーンショットを参照してください:

3。 次に、抽出された単語を出力する宛先範囲を指定し、[ OK (Comma Separated Values) ボタンをクリックして、各々のジョブ実行の詳細(開始/停止時間、変数値など)のCSVファイルをダウンロードします。

あなたがチェックした場合 列に分割 上記の[セルの分割]ダイアログのオプションでは、すべての単語がすべてのテキスト文字列から抽出され、垂直方向に一覧表示されます。

あなたがチェックした場合 行に分割 上記の[セルの分割]ダイアログのオプションでは、すべての単語がすべてのテキスト文字列から抽出され、水平方向に一覧表示されます。


素晴らしいツールを使用してExcelのテキスト文字列からn番目の単語を抽出します

Kutools for Excelをインストールしている場合は、数式ヘルパー>セル内のn番目の単語の抽出機能を使用して、指定したセルからn番目の単語を簡単にすばやく抽出できます。

Kutools for Excel - Excel に必要な 300 以上のツールが詰め込まれています。 クレジット カードは必要なく、全機能を備えた 30 日間の無料トライアルをお楽しみください。 ダウンロード中!

1。 抽出した単語を配置するセルを選択し、をクリックします クツール > フォーミュラヘルパー > フォーミュラヘルパー この機能を有効にします。

2。 Formulas Helperダイアログで、次のようにしてください。
(1)選択 テキスト 数式タイプ ドロップダウンリスト;
(2)クリックしてハイライト セル内のn番目の単語を抽出します セクションに 式を選択してください リストボックス;
で(3) セル ボックスで、単語を抽出するセルを指定します。
(4)In N番目 ボックスに、番号を指定します。

3。 クリック Ok ボタン。 必要に応じて、数式セルのオートフィルハンドルをドラッグし、数式を他のセルにコピーしてください。


デモ:テキスト文字列から各単語を抽出し、水平方向または垂直方向にリストします


Kutools for Excel: 300 を超える便利なツールをすぐに利用できます。 機能制限なしの 30 日間の無料トライアルを今すぐ始めてください。 今すぐダウンロード!

関連記事:

最高のオフィス生産性向上ツール

🤖 Kutools AI アシスタント: 以下に基づいてデータ分析に革命をもたらします。 インテリジェントな実行   |  コードを生成  |  カスタム数式の作成  |  データを分析してグラフを生成する  |  Kutools関数を呼び出す...
人気の機能: 重複を検索、強調表示、または識別する   |  空白行を削除する   |  データを失わずに列またはセルを結合する   |   数式なしのラウンド ...
スーパールックアップ: 複数の基準の VLookup    複数の値の VLookup  |   複数のシートにわたる VLookup   |   ファジールックアップ ....
詳細ドロップダウン リスト: ドロップダウンリストを素早く作成する   |  依存関係のドロップダウン リスト   |  複数選択のドロップダウンリスト ....
列マネージャー: 特定の数の列を追加する  |  列の移動  |  Toggle 非表示列の表示ステータス  |  範囲と列の比較 ...
注目の機能: グリッドフォーカス   |  デザインビュー   |   ビッグフォーミュラバー    ワークブックとシートマネージャー   |  リソースライブラリ (自動テキスト)   |  日付ピッカー   |  ワークシートを組み合わせる   |  セルの暗号化/復号化    リストごとにメールを送信する   |  スーパーフィルター   |   特殊フィルター (太字/斜体/取り消し線をフィルター...) ...
上位 15 のツールセット12 テキスト ツール (テキストを追加, 文字を削除する、...)   |   50+ チャート 種類 (ガントチャート、...)   |   40+ 実用的 (誕生日に基づいて年齢を計算する、...)   |   19 挿入 ツール (QRコードを挿入, パスから画像を挿入、...)   |   12 変換 ツール (数字から言葉へ, 通貨の換算、...)   |   7 マージ&スプリット ツール (高度な結合行, 分割セル、...)   |   ... もっと

Kutools for Excel で Excel スキルを強化し、これまでにない効率を体験してください。 Kutools for Excelは、生産性を向上させ、時間を節約するための300以上の高度な機能を提供します。  最も必要な機能を入手するにはここをクリックしてください...

説明


Officeタブは、タブ付きのインターフェイスをOfficeにもたらし、作​​業をはるかに簡単にします

  • Word、Excel、PowerPointでタブ付きの編集と読み取りを有効にする、パブリッシャー、アクセス、Visioおよびプロジェクト。
  • 新しいウィンドウではなく、同じウィンドウの新しいタブで複数のドキュメントを開いて作成します。
  • 生産性を 50% 向上させ、毎日何百回もマウス クリックを減らすことができます!
Comments (38)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I've created the FindWord custom function as described and it worked perfectly but it stopped working the next day. I looked in the VBA window and the Module is still there. Any idea why the function is not working anymore?
This comment was minimized by the moderator on the site
Dark Chocolate 25gm box 12 pcs

Dark Chocolate 20gm*24 box

White Chocolate 15gm

White Chocolate 25gm*24

Biscuits W/Marshmallow300gm

Chocolate 40gm

Can some plz help to extract the numbers before "gm", for example : 25,20,15,25,300,40
This comment was minimized by the moderator on the site
Hi I would like to know how to use the VBA model but I have sentences of only one word, and i would like to pick the first word even if there is only one word.

Thank you
This comment was minimized by the moderator on the site
Hi Maura,
The VBA cannot extract the first word if there is only word in the cell. However, it’s recommended to apply the Text to Column to extract the first word of every cell in a column quickly.
1. Select the column, copy, and paste in a blank column.
2. Keep the new column selected, click Data > Text to Column.
3. In the Text column dialog, select Delimited, and then check Space as delimiters, and finally click Finish.
4. Now all words are separated by space. For the extracted words, you can remove all columns except the first one.
This comment was minimized by the moderator on the site
i want to remove the last word in cell and data is like this "/Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf/Cdtr/CtctDtls/FaxNb" can i have formula
This comment was minimized by the moderator on the site
Thanks so much for these! I have a question, though: how do I extract a number or group of numbers from a cell or textbox? For instance, if I have [37.5" x 21'] in cell A1, how could extract 37.5 into A2? There could be any number of characters and numbers in A1, but I'll always want the first number to the left of the "X", and the first number to the right. Not sure if you've covered something like this elsewhere, so I thought I'd ask here. (Not sure if this went through the first time, so here it is again.)
This comment was minimized by the moderator on the site
Thank you! It works fine called in a Sub.
This comment was minimized by the moderator on the site
the original formula isn't working for me, I keep getting #NAME?, anyone able to help? I am using Excel 2013 and this VBA would save me sooooo much time
This comment was minimized by the moderator on the site
The original VBA code posted here would save me so much time, however whenever I type in the =findword formula, I then get #NAME?, anyone able to help me? I am using Excel 2013
This comment was minimized by the moderator on the site
Hi, I am having cell with values like SAN_UN_TC1,SAN_UN_TC2,PEP_HR_TC1 I would like to extract first words liek SAN /PEP into one cell and words liek UN/HR to another cell How could i do it, Any help is appreciated. Thanks, Shiva
This comment was minimized by the moderator on the site
If number of characters in string (SAN_UN_TC1) is fixed (3_2_3), it's simple: column 1: =LEFT(B15,3) column 2: =MID(B15,5,2) column 3: =RIGHT(B15,3)
This comment was minimized by the moderator on the site
Many thanks for sharing VBA code....saved me a lot of time
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations