How to extract characters before a specific character "LEFT and FIND functions" Excel (Excel)

Excel Functions
The article contains advertisements.

下図のように文字列の後に余分なデータが入っていて、余分なデータより左側の文字列のみ抽出したい場合、文字数が一定では無いため単純にLEFT関数だけで抽出ができません。

「A2」セルの金額を含まない左側だけを表示させたい

."A2The cell's "$20」マークより左側を抜き出す関数

=LEFT(A2,FIND("\",A2)-1)

In the following sections, we will explain the concept of this function.

特定の文字より前を抽出する方法はHow to extract after a specific character "RIGHT function and FIND function" Excel (Excel).

LEFT関数の使い方

LEFT関数はセルの文字列のうち右から○文字を抜き出すという関数です。

=LEFT(文字列,[文字数])

Both full-width and half-width characters are counted as one character.

「A2」セルの左から6文字を表示させたい

This time, in the state shown in the above figure, the "A2」セルから左側の6文字の文字列を抜き出すためには「文字列」は「A2cell, the "number of characters" is6characters, so enter the following

=LEFT(A2,6)

すると、下図のように金額以外の文字列を表示させることが出来ました。

金額以外の文字列だけを表示させることが出来た

しかしこの関数を同様に下のセルにも反映させると、下図のようにすべて6文字だけ抽出してしまうので、金額の一部が表示されてしまっていたり文字全体を表示することが出来ていなかったりします。

「B3」セルから「B5」セルまでの表示結果がおかしい

これは各セルの文字列が6文字とは限らないため、このような結果になってしまいました。

If the location of the character you want to extract moves from cell to cell, you can use the "FIND function" to solve this problem.

How to use the FIND function

The FIND function returns an integer that indicates how many characters of a particular string are present in a cell.

=FIND(search string,target,[start position])

Both full-width and half-width characters are counted as one character.

The "³" symbol is replaced by "A2To find out how many characters are in the "∗" column, enter the function as shown below.

=FIND("\", "}", "}", "}")A2)

The number "7" was returned as shown in the figure below.

The "³" mark is found to be the seventh character from the left.

これは「$20」マークが左から数えて「7文字目」であるためです。

これをLEFT関数に反映させるために以下のように関数を記載してみます。

=LEFT(A2,FIND("\",A2))

すると以下のように「$20」マークまで表示されてしまいました。

余分な「¥」マークまで表示されてしまった

これは、「$20」マークが7文字目であり、左から7文字目までを表示させているためです。
これを回避するためにFIND関数の後に「-1」を記載してみます。

=LEFT(A2,FIND("\",A2)-1)

これを「B2」セルから「B5」セルまで反映させると下図のように文字数に合わせて正しく表示させることが出来ました。

全てのセルで金額を除いた文字列が正しく表示されました。

Conclusion

今回は特定の文字から左側を抽出する方法を解説しましたが、特定の文字から右側を抽出したい場合はHow to extract after a specific character "RIGHT function and FIND function" Excel (Excel)article for more information.

LEFT関数の使い方はExcel (Excel) RIGHT and LEFT functions to extract a specific number of characters from the right or left of a stringIt is also explained in

Comment

Copied title and URL