Excel精英培训网

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

[已解决]删除满足条件的行

[复制链接]
发表于 2016-11-23 13:24 | 显示全部楼层 |阅读模式
       新手请教,这个宏是删除满足这个日期之前的所有数据,比如说,删除今天之前2个月的数据,就输入2.可是我这个宏不知道怎么搞的全删了。实在搞不懂。请教高手。郁闷。学这个真难。
最佳答案
2016-11-23 13:41
Private Sub CommandButton1_Click()
    Dim l As Integer
    Dim y%, m%, d%
    y = Year(Now())
    m = Month(Now())
    d = Day(Now())
    Dim xdata
    xdata = Date
    a = Range("a65536").End(xlUp).Row - 1
    l = Application.InputBox("你要删除几个月请输入", "操作提示", "0", 100, 100)
    xdata = DateSerial(y, m - l, d)
    For i = a To 1 Step -1    '在表格行循环
        If xdata > Cells(i, 1).Value Then
            Cells(i, 1).EntireRow.Delete    '是的删除
        Else
        End If
    Next
End Sub


1个颜色是1个错误,共3个。


删除所满足条件的行.rar

9.17 KB, 下载次数: 11

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
 楼主| 发表于 2016-11-23 13:25 | 显示全部楼层
Private Sub CommandButton1_Click()
Dim l As Integer
Dim y%, m%, d%
y = Year(Now())
m = Month(Now())
d = Day(Now())
Dim xdata
xdata = Date
a = Range("a65536").End(xlUp).Row - 1
l = Application.InputBox("你要删除几个月请输入", "操作提示", "0", 100, 100)
xdata = DateSerial(y, m - l, d)
    For i = a To 2 Step -1 '在表格行循环
             If xdate < Cells(i, 1).Value Then
                 Cells(i, 1).EntireRow.Delete '是的删除
             Else
             End If
     Next
End Sub
这个是代码
回复

使用道具 举报

发表于 2016-11-23 13:41 | 显示全部楼层    本楼为最佳答案   
Private Sub CommandButton1_Click()
    Dim l As Integer
    Dim y%, m%, d%
    y = Year(Now())
    m = Month(Now())
    d = Day(Now())
    Dim xdata
    xdata = Date
    a = Range("a65536").End(xlUp).Row - 1
    l = Application.InputBox("你要删除几个月请输入", "操作提示", "0", 100, 100)
    xdata = DateSerial(y, m - l, d)
    For i = a To 1 Step -1    '在表格行循环
        If xdata > Cells(i, 1).Value Then
            Cells(i, 1).EntireRow.Delete    '是的删除
        Else
        End If
    Next
End Sub


1个颜色是1个错误,共3个。


回复

使用道具 举报

 楼主| 发表于 2016-11-23 13:45 | 显示全部楼层
好,我改下试
回复

使用道具 举报

 楼主| 发表于 2016-11-23 13:50 | 显示全部楼层
爱疯,你太牛了。我是个粗心的人,不知道适不适合弄这个。我要改行做这个。
回复

使用道具 举报

发表于 2016-11-23 13:55 | 显示全部楼层
这个只要不马虎就行了
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-19 13:17 , Processed in 0.322101 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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