9
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ExcelでTRIM関数が効かない場合の対処

Last updated at Posted at 2017-11-23

Excel関数のTRIM()が効かない!

【事象】
・WebからデータをコピーしてExcelに貼り付けると、見えない空白が存在する
 →文字列比較しても正しい結果が得られなかったりする
【原因】
・Webからデータを取得すると、見えない空白(スペース、ブランク)が存在するため
・見えない空白の正体は文字コード160、HTMLでよく利用されるNBSP(ノーブレークスペース)
【対処】
・大量にあるならVBAを使うのも1つ。

sample
Function Nbsp2Sp(str As String) As String
    Dim nbsp(0 To 1) As Byte
    nbsp(0) = 160
    nbsp(1) = 0
    NBSP2SP = Replace(str, nbsp, " ")
End Function

・関数だけでよければ、下記のように記述すれば良い。

=TRIM(CLEAN(SUBSTITUTE(D4[対象セル],CHAR(160)," ")))
9
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?