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

Excelで大文字の前にスペースを挿入するにはどうすればよいですか?

次のように、単語間のすべてのスペースが誤って削除されたテキスト文字列のリストがあるとします。 データ間の空白行の挿入、そして今、あなたは単語を次のように区切るために大文字で各文字の前にスペースを追加したいと思います データ間に空白行を挿入する。 ExcelでスペースをXNUMXつずつ入力する代わりに、大文字の前にスペースをすばやく追加するにはどうすればよいですか?


ユーザー定義関数を使用して大文字の前にスペースを挿入する

残念ながら、Excelで大文字の前にスペースを追加する直接的な方法はありませんが、このタスクを解決するためにユーザー定義関数を作成することはできます。

1。 スペースを追加するテキスト文字列を含むワークシートをアクティブにします。

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

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

VBAコード:大文字の前にスペースを挿入します

Function AddSpaces(pValue As String) As String
'Update 20140723
Dim xOut As String
xOut = VBA.Left(pValue, 1)
For i = 2 To VBA.Len(pValue)
   xAsc = VBA.Asc(VBA.Mid(pValue, i, 1))
   If xAsc >= 65 And xAsc <= 90 Then
      xOut = xOut & " " & VBA.Mid(pValue, i, 1)
   Else
      xOut = xOut & VBA.Mid(pValue, i, 1)
   End If
Next
AddSpaces = xOut
End Function

4。 次に、このコードを保存して閉じ、ワークシートに戻って、この数式を入力します = addspaces(A1) データの横の空白のセルに、スクリーンショットを参照してください。
doc-add-spaces-before-uppercase-1

5。 次に、この数式を含める範囲に塗りつぶしハンドルをドラッグすると、すべての大文字の前にスペースが挿入されます。
doc-add-spaces-before-uppercase-1

セルの先頭/末尾/余分なスペースを簡単に削除

Excel用のKutools スペースを削除する このユーティリティを使用すると、Excelユーザーは、選択したセルからすべての先頭のスペース、末尾のスペース、余分なスペース、またはすべてのスペースをすばやく簡単に削除できます。


広告スペースを削除1

VBAコードで大文字の前にスペースを挿入します

これがあなたに有利な別のVBAコードです。次のようにしてください:

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

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

VBAコード:大文字の前にスペースを挿入します

Sub AddSpacesRange()
'Update 20140723
Dim Rng As Range
Dim WorkRng As Range
Dim xOut As String
Dim xValue As String
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
For Each Rng In WorkRng
    xValue = Rng.Value
    xOut = VBA.Left(xValue, 1)
    For i = 2 To VBA.Len(xValue)
       xAsc = VBA.Asc(VBA.Mid(xValue, i, 1))
       If xAsc >= 65 And xAsc <= 90 Then
          xOut = xOut & " " & VBA.Mid(xValue, i, 1)
       Else
          xOut = xOut & VBA.Mid(xValue, i, 1)
       End If
    Next
    Rng.Value = xOut
Next
Application.ScreenUpdating = True
End Sub

3。 次に、 F5 このコードを実行するためのキーを押すと、使用するデータ範囲を選択するためのプロンプトボックスが表示されます。
doc-add-spaces-before-uppercase-1

4。 そして、 OK このプロンプトボックスを閉じるには、大文字の前にスペースが一度に挿入されています。スクリーンショットを参照してください。
doc-add-spaces-before-uppercase-1


Kutools for Excelを使用して、すべての大文字の前にスペースを挿入します

Excel用のKutools テキストを追加 ユーティリティは、VBAマクロをバイパスし、Excelですべての大文字の前にスペースを簡単に挿入するのに役立ちます。

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

1。 大文字の前にスペースを挿入する範囲を選択し、 クツール > テキスト > テキストを追加。 スクリーンショットを参照してください:

2。 開いている[テキストの追加]ダイアログボックスで、にスペースを入力します テキスト ボックス、チェックボックス オプションに追加するだけ をクリックして 最初の文字は大文字です に追加するだけ ドロップダウンリスト。

3。 クリック Ok 次のスクリーンショットに示すように、すべての大文字の前にスペースを挿入するボタン:
doc大文字7の前にスペースを追加

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 (9)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
This function handles two problems that the given solution doesn't cover:
1. non-English text (with diacritical marks)
2. successive capitals that should not have spaces after them

` Private Function AddSpaces(sText As String)As String
' Inserts a space immediately before a capital letter, except when successive characters are each capitalized.
' Last Updated: 2022-07-04
'
Dim sRet As String, i As Integer, sChar As String, bPrevWasUCase As Boolean

sRet = Left(sText, 1)
For i = 2 To Len(sText)
sChar = Mid(sText, i, 1)
If sChar = UCase(sChar) And Not bPrevWasUCase Then
sRet = sRet & " " & sChar
bPrevWasUCase = True
Else
sRet = sRet & sChar
bPrevWasUCase = False
End If
Next i

AddSpaces= sRet
End Function`
This comment was minimized by the moderator on the site
Hello friend,

Thanks for your share. I tried your VBA code, but it doesn't work. Our VBA code can handle the non-english text. I have test the french text and spaces are successfully inserted before the capital letters.

Sincerely,
Mandy
This comment was minimized by the moderator on the site
Hello

First thanks a lot for your code example and the explanations. It works very well for my case.

I just have 1 Problem, some of the Strings contain words like URL, which should not be seperated.
Do you see a way to except for example "URL" from adding spaces?

Would be very nice if you can help. I tried already a while, but i dont know how to solve this..


Best regards
luca
This comment was minimized by the moderator on the site
hi wanna ask you if you found solution for you case, if you found solution please provide me with that
This comment was minimized by the moderator on the site
Hi,
Thanks for your comment and advice. I have sent your suggestion to the Kutools project team, I’m sure they’ll improve it soon.
This comment was minimized by the moderator on the site
Found a solution?
This comment was minimized by the moderator on the site
Hi there, your code works fantastic. Do you know how to adapt code 20140723 to work on multiple sheets? I would like to add spaces between capital letters throughout the entire workbook. Thanks!
This comment was minimized by the moderator on the site
i need a help in excel i want to find Uppercase in a cell. for example: Sagar Paul MBA 16:04 i want MBA to be highlighted
This comment was minimized by the moderator on the site
I hope you can see it and give it a trial. Sub Test() Dim Rg As Range, xCell As Range Dim i As Long Dim xChar As String Set Rg = Application.Selection For Each xCell In Rg For i = 1 To xCell.Characters.Count xChar = xCell.Characters(i, 1).Text If Asc(xChar) > 64 And Asc(xChar) < 91 Then xCell.Characters(i, 1).Font.Color = vbRed End If Next Next End Sub
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations