Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 3291|回复: 4

[已解决]怎么删除列?

[复制链接]
发表于 2014-1-9 11:23 | 显示全部楼层 |阅读模式
本帖最后由 hahada 于 2014-10-24 22:24 编辑

把第二行标题有dd  kk  aa  hh列的数据保留,其它标题所在的列删除

最佳答案
2014-1-9 12:07
  1.     Dim i As Integer
  2.     Application.ScreenUpdating = False
  3.     For i = Cells(2, Columns.Count).End(xlToLeft).Column To 1 Step -1
  4.         Select Case Cells(2, i).Value
  5.             Case "dd", "kk", "aa", "hh"
  6.             Case Else
  7.                 Columns(i).Delete
  8.         End Select
  9.     Next
  10.     Application.ScreenUpdating = True
  11.     MsgBox "ok"
复制代码
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2014-1-9 12:04 | 显示全部楼层
本帖最后由 yyyydddd8888 于 2014-1-9 12:05 编辑

请测试:

删除列.rar (7.7 KB, 下载次数: 16)

评分

参与人数 1 +1 收起 理由
hahada + 1 很给力!

查看全部评分

回复

使用道具 举报

发表于 2014-1-9 12:07 | 显示全部楼层    本楼为最佳答案   
  1.     Dim i As Integer
  2.     Application.ScreenUpdating = False
  3.     For i = Cells(2, Columns.Count).End(xlToLeft).Column To 1 Step -1
  4.         Select Case Cells(2, i).Value
  5.             Case "dd", "kk", "aa", "hh"
  6.             Case Else
  7.                 Columns(i).Delete
  8.         End Select
  9.     Next
  10.     Application.ScreenUpdating = True
  11.     MsgBox "ok"
复制代码
回复

使用道具 举报

 楼主| 发表于 2014-1-9 12:17 | 显示全部楼层
都不错,评哪个为最佳???
回复

使用道具 举报

发表于 2014-10-26 14:58 | 显示全部楼层
本帖最后由 sdfsdfs 于 2014-10-26 15:01 编辑

Sub Macro1()
Dim rng As Range, i&, j&
w = Array("dd", "kk")
For i = 2 To Cells(7, Columns.Count).End(xlToLeft).Column
    For j = 0 To UBound(w)
        If Cells(7, i) = w(j) Then
            If rng Is Nothing Then Set rng = Cells(7, i) Else Set rng = Union(rng, Cells(7, i)): Exit For
        End If
    Next
Next
If Not rng Is Nothing Then rng.EntireColumn.Delete
End Sub
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-26 11:26 , Processed in 0.343127 second(s), 14 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表