Excel精英培训网

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

[已解决]宏制作

[复制链接]
发表于 2017-6-23 17:07 | 显示全部楼层 |阅读模式
请大神们看附件
最佳答案
2017-6-23 18:20
  1. Sub 录入数据()
  2. Application.ScreenUpdating = False

  3. Dim Y
  4. Y = Range("H4")

  5.     x = 1
  6.     Do While Not (IsEmpty(Sheets(Y).Cells(x, 2).Value))
  7.         x = x + 1
  8.     Loop

  9.     n = x
  10.     z = 5
  11.     With Sheets("单据录入")
  12.         Do While Not (IsEmpty(.Cells(z, 2).Value))
  13.             z = z + 1
  14.         Loop
  15.         For k = 5 To z - 1
  16.                 Sheets(Y).Cells(x, 1) = .Cells(2, 5)
  17.                 Sheets(Y).Cells(x, 2) = .Cells(2, 3)
  18.                 Sheets(Y).Cells(x, 3) = .Cells(k, 2)
  19.                 Sheets(Y).Cells(x, 4) = .Cells(k, 3)
  20.                 Sheets(Y).Cells(x, 5) = .Cells(k, 4)
  21.                 Sheets(Y).Cells(x, 6) = .Cells(k, 5)
  22.             x = x + 1
  23.         Next k
  24.     End With
  25.     m = x - n
  26.     MsgBox "您已向" & Y & "中加入了" & m & "条记录,请在" & Y & "中进行确认!"
  27. Application.ScreenUpdating = True
  28. End Sub
复制代码

吴淼连进销存 - 副本.rar

24.23 KB, 下载次数: 7

发表于 2017-6-23 18:20 | 显示全部楼层    本楼为最佳答案   
  1. Sub 录入数据()
  2. Application.ScreenUpdating = False

  3. Dim Y
  4. Y = Range("H4")

  5.     x = 1
  6.     Do While Not (IsEmpty(Sheets(Y).Cells(x, 2).Value))
  7.         x = x + 1
  8.     Loop

  9.     n = x
  10.     z = 5
  11.     With Sheets("单据录入")
  12.         Do While Not (IsEmpty(.Cells(z, 2).Value))
  13.             z = z + 1
  14.         Loop
  15.         For k = 5 To z - 1
  16.                 Sheets(Y).Cells(x, 1) = .Cells(2, 5)
  17.                 Sheets(Y).Cells(x, 2) = .Cells(2, 3)
  18.                 Sheets(Y).Cells(x, 3) = .Cells(k, 2)
  19.                 Sheets(Y).Cells(x, 4) = .Cells(k, 3)
  20.                 Sheets(Y).Cells(x, 5) = .Cells(k, 4)
  21.                 Sheets(Y).Cells(x, 6) = .Cells(k, 5)
  22.             x = x + 1
  23.         Next k
  24.     End With
  25.     m = x - n
  26.     MsgBox "您已向" & Y & "中加入了" & m & "条记录,请在" & Y & "中进行确认!"
  27. Application.ScreenUpdating = True
  28. End Sub
复制代码
回复

使用道具 举报

发表于 2017-6-23 18:21 | 显示全部楼层
原来的代码没细看,用上工作表变量就可以
回复

使用道具 举报

 楼主| 发表于 2017-6-26 10:00 | 显示全部楼层
七彩屋 发表于 2017-6-23 18:21
原来的代码没细看,用上工作表变量就可以

谢谢您
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-27 22:54 , Processed in 0.306687 second(s), 12 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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