跳到主要内容

如何在Excel中快速删除多个空列?

有时,当您从某些来源(例如网页,CSV,文本等)将数据导入Microsoft Excel时,可能会有许多空列。 删除每个空列必须是耗时的。 因此,我们中的某些人寻求解决此问题的简便方法。 本文收集了一些技巧性的技巧,以帮助您快速删除多个空列。

使用公式删除工作表中的多个空列

使用VBA代码删除工作表中的多个空列

删除选区/活动工作表/整个工作簿中的多个空列,并提供有用的功能

使用VBA代码删除带有标题的多个空列


使用公式删除工作表中的多个空列

在Excel中,您可以应用公式来确定列是否为空白,然后使用 排序 功能可将所有空白列排序在一起,然后立即将其删除。 请这样做:

1。 在数据范围的顶部添加新行,请参见屏幕截图:

2。 然后将以下公式输入到单元格A1中,然后将填充手柄拖动到右侧以将此公式应用于其他单元格,如果该列为空白,则将显示TRUE,否则显示FALSE,请参见屏幕截图:

=COUNTA(A2:A1048576)=0

3。 然后选择包括助手行的数据范围,然后单击 时间 > 排序,请参见屏幕截图:

4。 在弹出 排序 对话框,单击 附加选项 按钮,在下面 排序选项 对话框中选择 从左到右排序 选项,请参见屏幕截图:

5。 点击 OK 按钮返回 排序 对话框,然后选择 第1行 来自 排序方式 下拉菜单,然后选择 单元格值排序 部分中,选择 最大到最小 来自 订购产品 部分,请参见屏幕截图:

6。 然后,所有空列都已排序在数据的左侧,现在,您只需要选择所有列,然后右键单击,选择 删除 要立即删除这些空白列,请参见屏幕截图:


使用VBA代码删除工作表中的多个空列

如果您想使用VBA宏,事情会变得容易得多。 以下VBA代码可能会对您有所帮助,请这样做:

1。 按住 其他 + F11 键,然后打开 Microsoft Visual Basic应用程序 窗口。

2。 点击 插页 > 模块,然后将以下宏粘贴到 模块 窗口。

VBA代码:删除选择中的多个空白列:

Sub DeleteEmptyColumns()'更新依据 Extendoffice
作为范围的Dim rng作为范围的Dim InputRng作为范围xTitleId =“ KutoolsforExcel”设置InputRng = Application.Selection设置InputRng = Application.InputBox(“ Range:”,xTitleId,InputRng.Address,类型:= 8)Application.ScreenUpdating = False对于i = InputRng.Columns.Count到1步骤-1设置rng = InputRng.Cells(1,i).EntireColumn如果Application.WorksheetFunction.CountA(rng)= 0然后rng.Delete End如果下一个Application.ScreenUpdating = True End Sub

3。 按 F5 键以运行此宏,然后在弹出对话框中选择所需的工作范围。 看截图:

4. 点击 OK,然后删除选择中的所有空列。 看截图:


删除选区/活动工作表/整个工作簿中的多个空列,并提供有用的功能

删除隐藏(可见)行和列 实用程序 Kutools for Excel 可以帮助您一次快速删除多个空行或列。

Tips:申请这个 删除隐藏(可见)行和列 功能,首先,您应该下载 Kutools for Excel,然后快速轻松地应用该功能。

安装后 Kutools for Excel,请这样做:

1。 点击 库工具 > 删除 > 删除隐藏(可见)行和列,请参见屏幕截图:

2。 在 删除隐藏(可见)行和列 对话框中,指定要从中应用操作的范围 在看 下拉列表。 (如果您选择 在选定范围内,则必须先选择要使用的范围。)然后检查 删除类型。 并选择 空白栏详细类型。 看截图:

3。 然后点击 OK。 并且空白列已从所选范围中删除。 看截图:


使用VBA代码删除带有标题的多个空列

有时,您可能希望删除工作表中仅包含标题的所有空列,以下VBA代码可以帮您一个忙,请执行以下步骤:

1。 按住 其他 + F11 键,然后打开 Microsoft Visual Basic应用程序 窗口。

2。 点击 插页 > 模块,然后将以下宏粘贴到 模块 窗口。

VBA代码:删除所有带有标题的空列

Sub deleteblankcolwithheader()
'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 column(s) with only a header row have 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键运行此代码,将弹出一个提示框,提醒您标题为空白的列将被删除,请参见屏幕截图:

4.然后,单击“确定”按钮,一次删除当前工作表中仅标题的所有空白列。 查看屏幕截图:


更多相关文章:

  • 在Excel中删除所有隐藏的行或列
  • 如果您有一个很大的工作簿,其中包含许多隐藏的行和列,而现在隐藏的数据不可用,则您想要删除所有这些。 您如何快速删除它们?
  • 在Excel中基于背景色删除行
  • 如何根据背景色删除整个行? 在此示例中,我需要删除所有单元格填充有蓝色背景色的所有行,如下面的屏幕截图所示。 通过本文,您将获得一些代码以在Excel中完成此任务。

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!

Comments (8)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
It deleted all my names in my first name column! Auuggh!
This comment was minimized by the moderator on the site
Thanks its very helpful page with basic excel option :)
This comment was minimized by the moderator on the site
Hi, can anyone guide how i can delete blank cells in a row or column...note whole blank column or rows... only blank cell i need to delete in a column
This comment was minimized by the moderator on the site
Hello,


try to implement below code
This comment was minimized by the moderator on the site
Hi, the thing which you are mentioned is so helpfull. I want a small help from your side. Daily am download the some files and using pivot prepared the reports. It is daily task for me and routine process. How can i do it with out using pivot. Ex: If i prepared the reports on yesterday in "A" Excel file. Next day in "A" Excel file just i replace the new "B" Excel file data. By this automatically report would be create? Is it possible?
This comment was minimized by the moderator on the site
Very helpful page. Thank you. :-) My challenge is that I have columns with headers, but no data in that column. Only the header is present. How would one go about deleting columns where there is no data, but the header is there? :o
This comment was minimized by the moderator on the site
the above details are very helpful for my personal use. Thanks for your guidance. M.KARTHIKEYAN :-)
This comment was minimized by the moderator on the site
I found it much simpler to go to the line after my last line of data, enter "Shift-Ctrl-End" to highlight all blank lines that followed(much faster), right click and enter "delete all rows/columns". The system didn't waste so much time searching this way and so it was clean in the blink of an eye and files that were 20 MB were dropped to a size of 20 kb.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations