Excel精英培训网

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

[已解决]增加一个条件,空白行不保存,谢谢!

[复制链接]
发表于 2014-6-15 23:30 | 显示全部楼层 |阅读模式
5学分
本帖最后由 wangby 于 2014-6-15 23:50 编辑

请在以下代码中增加空白行不保存,请看附件,谢谢!

  • Private Sub CommandButton1_Click()
  •     Dim i As Long, j&
  •     Dim arr
  •     Application.ScreenUpdating = False  '关闭屏幕刷新
  •     For i = 3 To Cells(Rows.Count, 1).End(xlUp).Row
  •         If Cells(i, "D") <> "" Then
  •             arr = Range(Cells(i, "N"), Cells(i, "Y"))
  •             With Sheets(Cells(i, 1).Value)
  •                 j = .Range("C:C").Find(Cells(i, "D")).Row
  •                 .Cells(j, "M").Resize(, UBound(arr, 2)) = arr
  •             End With
  •         End If
  •     Next i
  •     Application.ScreenUpdating = True   '打开屏幕刷新
  • End Sub

9.rar (50.66 KB, 下载次数: 8)

最佳答案

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2014-6-15 23:30 | 显示全部楼层    本楼为最佳答案   
  1. Private Sub CommandButton1_Click()
  2.     Dim i As Long, j&
  3.     Dim arr
  4.     Application.ScreenUpdating = False  '关闭屏幕刷新
  5.     For i = 3 To Cells(Rows.Count, 1).End(xlUp).Row
  6.         If Cells(i, "D") <> "" Then
  7.             arr = Range(Cells(i, "N"), Cells(i, "Y"))
  8.             If Application.Count(arr) Then
  9.                 With Sheets(Cells(i, 1).Value)
  10.                     j = .Range("C:C").Find(Cells(i, "D")).Row
  11.                     .Cells(j, "M").Resize(, UBound(arr, 2)) = arr
  12.                 End With
  13.             End If
  14.         End If
  15.     Next i
  16.     Application.ScreenUpdating = True   '打开屏幕刷新
  17. End Sub
复制代码
回复

使用道具 举报

 楼主| 发表于 2014-6-16 13:58 | 显示全部楼层
FnG 发表于 2014-6-16 01:35

谢谢完全OK。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-6-8 10:00 , Processed in 0.221194 second(s), 7 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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