Excel精英培训网

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

VBA 

[复制链接]
发表于 2015-12-31 21:25 | 显示全部楼层 |阅读模式
Sub 保存()
ThisWorkbook.Sheets("Sheet4").Activate

On Error GoTo 100
   Dim es As Range, a%
     If Sheet3.[g:g].Find([b4]) = Sheet4.[b4] Then
       MsgBox "已经保存过了!"
      Else
100:
        Set es = Cells.Find("*", , xlFormulas, , , xlPrevious)
        a = Application.CountA(Sheet3.[a:a])
        If es.Row = 5 Then MsgBox "没有填写内容": End
        Range([a6], es).Copy Sheet3.Cells(a + 1, 1)
        Sheet3.Cells(a + 1, "g").Resize(es.Row - 5) = [b4]
        Sheet3.Cells(a + 1, "h").Resize(es.Row - 5) = [f4]
     MsgBox "保存成功"
   End If
End Sub
我下面的两句代码好像不对,大师们能否指点一下?
  If Sheet3.[g:g].Find([b4]) = Sheet4.[b4] Then
  If es.Row = 5 Then MsgBox "没有填写内容": End
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2015-12-31 23:12 | 显示全部楼层
     由于没有与此程序对应附件数据,故不好准确判断何处出了问题
    你说可能 If es.Row = 5 Then MsgBox "没有填写内容": End 这句出错,我看更可能是前面的Set es = Cells.Find("*" 出了错。因cells前必须有引用的工作表对象,不象range,默认为当前激活的工作表,这一点我也亲身经历。
    其实,你可有程序语句中先加入一些自定义变象 如 rs=es.row,通过逐句调试,看rs的数值到底为多少,从中可找出错误的原因。你说的第一句错误我还没发现,也许没的与此对应的数据。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-8-16 08:21 , Processed in 0.332982 second(s), 4 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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