Excel精英培训网

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

[已解决]录制的宏执行时出错,大家帮忙看看

[复制链接]
发表于 2011-8-13 08:38 | 显示全部楼层 |阅读模式
捕获.PNG 捕获2.PNG

昨天在论坛高手的帮助下,解决了一个问题,就是去除表中销售目标一样的行,我自己录制了宏,希望能自动执行操作,结果在使用宏的时候,提示错误,也行问题就出在那个 “通用格式”上,我不知道怎么解决

大家帮忙看看,谢谢 我把宏也贴上来

Sub 去重复()
'
' 去重复 宏
'
'
    Cells.Select
    Cells.EntireColumn.AutoFit
    Range("C2:C14").Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    Range("B2:C14").Select
    Selection.RowDifferences(ActiveCell).Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorLight2
        .TintAndShade = 0.399975585192419
        .PatternTintAndShade = 0
    End With
    Range("C8").Select
    Application.FindFormat.Clear
    Application.FindFormat.NumberFormat = "G/通用格式"
    With Application.FindFormat
        .HorizontalAlignment = xlGeneral
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    With Application.FindFormat.Font
        .Name = "宋体"
        .FontStyle = "常规"
        .Size = 11
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .Underline = xlUnderlineStyleNone
        .ThemeColor = 2
        .TintAndShade = 0
        .ThemeFont = xlThemeFontMinor
    End With
    With Application.FindFormat.Borders(xlLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Application.FindFormat.Borders(xlRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Application.FindFormat.Borders(xlTop)
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Application.FindFormat.Borders(xlBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    Application.FindFormat.Borders(xlDiagonalDown).LineStyle = xlNone
    Application.FindFormat.Borders(xlDiagonalUp).LineStyle = xlNone
    With Application.FindFormat.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    Application.FindFormat.Locked = True
    Application.FindFormat.FormulaHidden = False
    Selection.EntireRow.Delete
End Sub
最佳答案
2011-8-13 09:21
本帖最后由 wbzxz 于 2011-8-13 09:22 编辑

  我看了你复制的代码,没有找到问题所在,不知道你是否修改过宏代码,也不太清楚当时录制代码是的具体环境,分析不出来。不过这种问题,应该这样就可以解决。
把这个代码放入sheet1表中

Sub quchongfu()
    Dim i As Long
    Dim endRow
    endRow = Range("A" & Rows.Count).End(xlUp).Row
    For i = endRow To 2 Step -1
        If Cells(i, 2) = Cells(i, 3) Then
            Cells(i, 1).EntireRow.Delete
        End If
    Next i

End Sub



详见附件:

工作簿2.zip (7.23 KB, 下载次数: 4)

工作簿2.zip

4.05 KB, 下载次数: 8

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2011-8-13 09:20 | 显示全部楼层
目的是去除表中销售目标一样的行?就是C列中相同数字的行保留一行?
如果做一个去除后的结果示例,就清楚了。
录制宏是学习VBA的很好的方法,但是都要经过修改的。
回复

使用道具 举报

发表于 2011-8-13 09:21 | 显示全部楼层    本楼为最佳答案   
本帖最后由 wbzxz 于 2011-8-13 09:22 编辑

  我看了你复制的代码,没有找到问题所在,不知道你是否修改过宏代码,也不太清楚当时录制代码是的具体环境,分析不出来。不过这种问题,应该这样就可以解决。
把这个代码放入sheet1表中

Sub quchongfu()
    Dim i As Long
    Dim endRow
    endRow = Range("A" & Rows.Count).End(xlUp).Row
    For i = endRow To 2 Step -1
        If Cells(i, 2) = Cells(i, 3) Then
            Cells(i, 1).EntireRow.Delete
        End If
    Next i

End Sub



详见附件:

工作簿2.zip (7.23 KB, 下载次数: 4)
回复

使用道具 举报

 楼主| 发表于 2011-8-13 09:23 | 显示全部楼层
回复 蓝桥玄霜 的帖子

是用来审计用的

第一个月的数据和第二个月的数据比较,如果有变化,就审计。忽略没变化的数据

所以我的目的是,只对表中的两个数据列进行比较。找到数据相同无变化的数据,然后删除所在行


回复

使用道具 举报

 楼主| 发表于 2011-8-13 09:26 | 显示全部楼层
回复 wbzxz 的帖子

谢谢高手
你的代码短小精悍,问题一下就解决了,谢谢

真是难者不会,会者不难啊,谢谢
回复

使用道具 举报

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

本版积分规则

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

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

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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