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

Excelのセルから数字以外の文字を削除するにはどうすればよいですか?

そのようなデータがたくさん含まれているワークシートがあるとします。 ABCD4578124ユイオー、および数字以外の文字のみを削除したい  ABCデュイオー ただし、数字はセルに入れておきます。 もちろん、これらの文字をXNUMXつずつ削除することもできますが、ここでは、次のようにセルから数字以外の文字をすばやく削除できます。

VBAコードで数字以外の文字を削除する

ワンクリックで数字以外の文字を削除する便利なツール


VBAコードで数字以外の文字を削除する

VBAコードを使用して範囲から数字以外の文字を削除するには、次のようにします。

1. Developer > ビジュアルベーシック を開く アプリケーション用のMicrosoftVisual Basic 窓。 の中に アプリケーション用のMicrosoftVisual Basic ウィンドウ、クリック インセット > モジュール、次に、次のコードをコピーしてモジュールに貼り付けます。

VBA:数字以外の文字をすべて削除します

Sub RemoveNotNum()
'Updateby Extendoffice
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
For Each Rng In WorkRng
    xOut = ""
    For i = 1 To Len(Rng.Value)
        xTemp = Mid(Rng.Value, i, 1)
        If xTemp Like "[0-9]" Then
            xStr = xTemp
        Else
            xStr = ""
        End If
        xOut = xOut & xStr
    Next i
    Rng.Value = xOut
Next
End Sub

2。 次に、 コードを実行するためのボタン、ポップアップで Kutools for Excel ダイアログボックスで、削除する数字以外の文字を含む範囲を選択し、[ OK ボタン。 スクリーンショットを参照してください:

docは数字以外の文字を削除します1コピー

3。 次に、選択した範囲内のすべての非数字が削除されます。

docは数字以外の文字を削除します2

小数点付きの数値の場合は、次のVBAを使用できます。

Sub RemoveNotNum()
'Updateby Extendoffice
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
For Each Rng In WorkRng
    xOut = ""
    For i = 1 To Len(Rng.Value)
        xTemp = Mid(Rng.Value, i, 1)
        If xTemp Like "[0-9.]" Then
            xStr = xTemp
        Else
            xStr = ""
        End If
        xOut = xOut & xStr
    Next i
    Rng.Value = xOut
Next
End Sub

以下のスクリーンショットのように結果を確認できます。

docは数字以外の文字を削除します3


ワンクリックで数字以外の文字を削除する便利なツール

範囲内の数字以外の文字を削除するには、 Kutools for Excelさん 文字を削除する ユーティリティはワンクリックでそれを行うことができます。

Kutools for Excel : 300以上の便利なExcelアドインがあり、30日以内に制限なしで無料で試すことができます. 

インストールした後 Kutools for Excel、以下のようにしてください:

1。 数字以外の文字を削除する範囲を強調表示します。 クリック クツール > テキスト > 文字を削除する.

docは数字以外の文字を削除します4

2。 の中に 文字を削除する ダイアログボックスで 非数値 内のオプション 文字を削除する セクションをクリックし、 OK or 申し込む ボタン。 また、数字以外の文字はすぐに選択から削除されます。 スクリーンショットを参照してください:

docは数字以外の文字を削除します5

クリックしてKutoolsfor Excelと無料トライアルを今すぐダウンロードしてください!

詳細については、 文字を削除する Kutools for Excelについては、次のWebサイトをご覧ください。 文字機能の説明を削除します。


デモ:セルから数字、アルファベット、印刷不可、または英数字を削除します

Kutools for Excel:300以上の便利なExcelアドインがあり、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 (13)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
HI Thanks for the coding, i am getting the syntax error highlighted on For i = 1 To Len(Rng.Value) and the debug Sub RemoveNotNum() is highlighted in yellow.. kindly advice.
This comment was minimized by the moderator on the site
The VBA works great. I modified it to always work on a column, as shown:

For Each Cell In Range("B2:B" & ActiveSheet.UsedRange.Rows.Count)

xOut = ""

For i = 1 To Len(Cell.Value)

xTemp = Mid(Cell.Value, i, 1)

If xTemp Like "[0-9]" Then

xStr = xTemp

Else

xStr = ""

End If

xOut = xOut & xStr

Next i

Cell.Value = xOut

Next

I also used this to sort a column by the last digit, changing the last part to Cell.Value = Right(xOut, 1) then sorting it numerically.
This comment was minimized by the moderator on the site
Send me it on my email id
This comment was minimized by the moderator on the site
Hi, I want to use this macro but want to pre-define a range. Can you please let me know how to pre-define the range. Thanks, Samit
This comment was minimized by the moderator on the site
Just wanted to let you know that if the string starts with zero(s), or starts with letters, followed by zero(s), followed by the rest of the string this will remove all of the beginning zeroes. This is weird because it doesn't remove the zero(s) if they are between other non-zero numbers within the string, only if they start the string or are the first numbers after the initial letters in a string. Example. 0060100 would come out as 60100 PFF057726 would come out as 57726. Let me know if you have an explanation for this and can think of a solution. Thank you.
This comment was minimized by the moderator on the site
Thanx Guys for such a nice work. The script is awesome and it worked for. Keep it up guys.
This comment was minimized by the moderator on the site
Use this Formaula for replacing the existing character with the new one =SUBSTITUTE(text,old_text,new_text,[instance_num]) for ex-=SUBSTITUTE(TRIM(G1),"/","") Wish U all Happy Easter 2015
This comment was minimized by the moderator on the site
I received an error when I hit the > run button in the developer: Compile Error: Expected:end of statement and the word "non" in non-numeric is highlighted
This comment was minimized by the moderator on the site
Wow. that worked , exactly what I needed. Thanks,
This comment was minimized by the moderator on the site
Awesome Worked GREAT!!!!!!!!
This comment was minimized by the moderator on the site
wouldn't be better to replace the input-box method by just setting WorkRng like this: Set WorkRng = Intersect(ActiveSheet.UsedRange, Selection) that way if user select a entire column it wouldn't generate any error.
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