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

Excelでヘッダー付きの空の列を削除するにはどうすればよいですか?

複数の列を含む大きなワークシートがあり、一部の列にはヘッダーのみが含まれている場合、次のスクリーンショットを表示するには、ヘッダーのみの空の列を削除します。 これはExcelですばやく簡単に解決できますか?

docはヘッダー1のある空白の列を削除します

VBAコードを使用して、ヘッダー付きの空の列を削除します

Kutools for Excelを使用して、範囲/ワークシート/ワークブック内の複数の空の列を削除します


矢印青い右バブル VBAコードを使用して、ヘッダー付きの空の列を削除します

Excelでは、手動でXNUMXつずつ削除する以外に、このジョブを直接処理する方法はありませんが、ここでは、コードを紹介します。次のようにしてください。

1. 押したまま Alt + F11 キーを押すと、 アプリケーション向け Microsoft Visual Basic 窓。

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

VBAコード:ヘッダー付きの空の列を削除します:

Sub Macro1()
'updateby Extendoffice
    Dim xEndCol As Long
    Dim I As Long
    Dim xDel As Boolean
    On Error Resume Next
    xEndCol = Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
    If xEndCol = 0 Then
        MsgBox "There is no data on """ & ActiveSheet.Name & """ .", vbExclamation, "Kutools for Excel"
        Exit Sub
    End If
    Application.ScreenUpdating = False
    For I = xEndCol To 1 Step -1
        If Application.WorksheetFunction.CountA(Columns(I)) <= 1 Then
            Columns(I).Delete
            xDel = True
        End If
    Next
    If xDel Then
        MsgBox "All blank and column(s) with only a header row have now been deleted.", vbInformation, "Kutools for Excel"
    Else
        MsgBox "There are no Columns to delete as each one has more data (rows) than just a header.", vbExclamation, "Kutools for Excel"
    End If
    Application.ScreenUpdating = True
End Sub

3。 次に、 F5 このコードを実行するためのキーを押すと、ヘッダー付きの空白の列が削除されることを通知するプロンプトボックスが表示されます。スクリーンショットを参照してください。

docはヘッダー2のある空白の列を削除します

4。 そして、 OK ボタンをクリックすると、現在のワークシートのヘッダーのみを含むすべての空白の列が一度に削除されます。

Note:空白の列がある場合は、それらも削除されます。


矢印青い右バブル Kutools for Excelを使用して、範囲/ワークシート/ワークブック内の複数の空の列を削除します

場合によっては、空白の列を削除するだけで済みます。 Kutools for Excelさん 非表示の(表示されている)行と列を削除する ユーティリティは、このタスクを簡単に完了するのに役立ちます。

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

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

1。 削除する必要がある空白の列を含む列範囲を選択します。

2。 次に、をクリックします クツール > 削除 > 非表示の(表示されている)行と列を削除する、スクリーンショットを参照してください:

3。 の中に 非表示の(表示されている)行と列を削除する ダイアログボックスで、必要に応じて[探す場所]ドロップダウンから削除スコープを選択できます。 コラム タイプを削除 セクションをクリックしてから、 空白の列 詳細タイプ セクション、スクリーンショットを参照してください:

docはヘッダー4のある空白の列を削除します

4。 次に、をクリックします Ok ボタンをクリックすると、空の列のみが一度に削除されます。 スクリーンショットを参照してください:

docはヘッダー5のある空白の列を削除します

ヒント:この強力な機能を使用すると、必要に応じて、空白行、表示されている列または行、非表示の列または行を削除することもできます。

今すぐExcel用の無料ダウンロードKutoolsをクリックしてください!

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

🤖 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 (10)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
All I keep getting is "There are no Columns to delete as each one has more data (rows) than just a header." Yet I know for a fact I have about 700 columns with a header and no data. I have a spreadsheet with over 900 columns and only 200ish have data below the header. Another macro worked but I had to delete the header row. So I know this macro is not working correctly. What's up?
This comment was minimized by the moderator on the site
Hello, Paul
The VBA code works well if there is only one header row in the worksheet, if there are two or more header rows, it will pop out the prompt message you said.
So you need to check out if there are hidden heading rows in your data.
Thank you!
This comment was minimized by the moderator on the site
Hello, I have the same issue, I know by fact that I have a lot of columns that have only headers but the same Error "There are no Columns to delete as each one has more data (rows) than just a header." and I have checked there are no hidden rows in the data.
Can anyone help me ?
This comment was minimized by the moderator on the site
Hi, Simoch
In this case, you can upload your Excel file attachment here, so that we can help to check the problem if you don't mind.
Thank you!
This comment was minimized by the moderator on the site
Dear skyyang no need, It worked perfecty now !! thank you so much for that VBA code !
Rated 5 out of 5
This comment was minimized by the moderator on the site
Amazing! You are correct. There must have been something hidden. Everything is working great now. Thank you so much for the quick reply.
This comment was minimized by the moderator on the site
Can this be saved in one spreadsheet and run on other files?
This comment was minimized by the moderator on the site
Works perfectly. Greatly appreciated
This comment was minimized by the moderator on the site
OMG, this is genius!!! thank you
This comment was minimized by the moderator on the site
Hi, Thanks for the nice code above. Is it free to use?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations