Excel精英培训网

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

[已解决]录入时候格数不确定,少了的时候 老是空着几个格

[复制链接]
发表于 2015-11-19 13:40 | 显示全部楼层 |阅读模式
录入时候格数不确定,少了的时候 老是空着几个格
如何判读一下不让他空着格
最佳答案
2015-11-19 14:50
规整一下你的代码,可改为
  1. Sub 录入数据()
  2.     Dim sh As Worksheet
  3.     Application.ScreenUpdating = False
  4.     Set sh = Sheets("入库")
  5.     With Sheets("单据录入")
  6.         If .Range("J1") = "入库" Then
  7.             r = sh.[a65536].End(3).Row + 1   '入库表输入起始行
  8.             Z = .[c6].End(xlDown).Row      '当前表最大记录行
  9.             a = .Range("B:B").Find("合计").Offset(0, 2)     '合计:件数
  10.             b = .Range("B:B").Find("合计").Offset(0, 3)    '合计:数量
  11.             For k = 7 To Z
  12.                 x = r + k - 7
  13.                 sh.Cells(x, 1) = .Cells(5, 8)  '日期
  14.                 sh.Cells(x, 13) = .Cells(7, 11)  '基价
  15.                 sh.Cells(x, 14) = .Cells(7, 12)  '仓库
  16.                 sh.Cells(x, 15) = .Cells(7, 13)  '备注
  17.                 sh.Cells(x, 12) = .Cells(7, 10)  '含税
  18.                 sh.Cells(x, 2) = .Cells(4, 8)  '编号
  19.                 sh.Cells(x, 3) = .Cells(k, 3)  '规格
  20.                 sh.Cells(x, 4) = .Cells(k, 4)  '件数
  21.                 sh.Cells(x, 5) = .Cells(k, 5)  '数量
  22.                 sh.Cells(x, 6) = .Cells(k, 6)  '单价
  23.                 sh.Cells(x, 7) = .Cells(k, 7)  '金额
  24.                 sh.Cells(x, 8) = .Cells(4, 2)  '车号
  25.                 sh.Cells(x, 9) = .Cells(5, 2)  '单位
  26.             Next k
  27.             sh.Cells(x, 10) = a  '合计:件数
  28.             sh.Cells(x, 11) = b  '合计:数量
  29.             MsgBox "您已向“入库”中加入了" & Z - 6 & "条记录,请在“入库”中进行确认!"
  30.         End If
  31.     End With
  32.     Application.ScreenUpdating = True
  33. End Sub
复制代码
QQ截图20151119133213.png
QQ截图20151119133226.png

11-19号更新.rar

361.81 KB, 下载次数: 4

发表于 2015-11-19 14:23 | 显示全部楼层
回复

使用道具 举报

发表于 2015-11-19 14:35 | 显示全部楼层
代码不作大的改动,可这样改:
  1. Sub 录入数据()
  2. Application.ScreenUpdating = False
  3. If Range("J1") = "入库" Then
  4.     x = 1
  5.     Do While Not (IsEmpty(Sheets("入库").Cells(x, 4).Value))
  6.         x = x + 1
  7.     Loop
  8.     '入库单的行数据统计
  9.     n = x
  10.     Z = [c6].End(xlDown).Row
  11.     a = Sheets("单据录入").Range("B:B").Find("合计", LookIn:=xlValues, LOOKAT:=xlWhole, SEARCHORDER:=xlByColumns).Offset(0, 2)
  12.     b = Sheets("单据录入").Range("B:B").Find("合计", LookIn:=xlValues, LOOKAT:=xlWhole, SEARCHORDER:=xlByColumns).Offset(0, 3)
  13.     With Sheets("单据录入")
  14. '        Do While Not (IsEmpty(.Cells(Z, 3).Value))
  15. '            Z = Z + 1
  16. '        Loop
  17.         For k = 7 To Z
  18.                 Sheets("入库").Cells(x, 1) = .Cells(5, 8)  '日期
  19.                 Sheets("入库").Cells(x, 13) = .Cells(7, 11)  '基价
  20.                 Sheets("入库").Cells(x, 14) = .Cells(7, 12)  '仓库
  21.                 Sheets("入库").Cells(x, 15) = .Cells(7, 13)  '备注
  22.                 Sheets("入库").Cells(x, 12) = .Cells(7, 10)  '含税
  23.                 Sheets("入库").Cells(x, 2) = .Cells(4, 8)  '编号
  24.                 Sheets("入库").Cells(x, 3) = .Cells(k, 3)  '规格
  25.                 Sheets("入库").Cells(x, 4) = .Cells(k, 4)  '件数
  26.                 Sheets("入库").Cells(x, 5) = .Cells(k, 5)  '数量
  27.                 Sheets("入库").Cells(x, 6) = .Cells(k, 6)  '单价
  28.                 Sheets("入库").Cells(x, 7) = .Cells(k, 7)  '金额
  29.                 Sheets("入库").Cells(x, 8) = .Cells(4, 2)  '车号
  30.                 Sheets("入库").Cells(x, 9) = .Cells(5, 2)  '单位
  31.                   x = x + 1
  32.         Next k
  33.     End With
  34.     Sheets("入库").Cells(x - 1, 10) = a '单位
  35.     Sheets("入库").Cells(x - 1, 11) = b '单位
  36.     m = x - n
  37.     MsgBox "您已向“入库”中加入了" & m & "条记录,请在“入库”中进行确认!"
  38. End If
  39. End Sub
复制代码
回复

使用道具 举报

发表于 2015-11-19 14:50 | 显示全部楼层    本楼为最佳答案   
规整一下你的代码,可改为
  1. Sub 录入数据()
  2.     Dim sh As Worksheet
  3.     Application.ScreenUpdating = False
  4.     Set sh = Sheets("入库")
  5.     With Sheets("单据录入")
  6.         If .Range("J1") = "入库" Then
  7.             r = sh.[a65536].End(3).Row + 1   '入库表输入起始行
  8.             Z = .[c6].End(xlDown).Row      '当前表最大记录行
  9.             a = .Range("B:B").Find("合计").Offset(0, 2)     '合计:件数
  10.             b = .Range("B:B").Find("合计").Offset(0, 3)    '合计:数量
  11.             For k = 7 To Z
  12.                 x = r + k - 7
  13.                 sh.Cells(x, 1) = .Cells(5, 8)  '日期
  14.                 sh.Cells(x, 13) = .Cells(7, 11)  '基价
  15.                 sh.Cells(x, 14) = .Cells(7, 12)  '仓库
  16.                 sh.Cells(x, 15) = .Cells(7, 13)  '备注
  17.                 sh.Cells(x, 12) = .Cells(7, 10)  '含税
  18.                 sh.Cells(x, 2) = .Cells(4, 8)  '编号
  19.                 sh.Cells(x, 3) = .Cells(k, 3)  '规格
  20.                 sh.Cells(x, 4) = .Cells(k, 4)  '件数
  21.                 sh.Cells(x, 5) = .Cells(k, 5)  '数量
  22.                 sh.Cells(x, 6) = .Cells(k, 6)  '单价
  23.                 sh.Cells(x, 7) = .Cells(k, 7)  '金额
  24.                 sh.Cells(x, 8) = .Cells(4, 2)  '车号
  25.                 sh.Cells(x, 9) = .Cells(5, 2)  '单位
  26.             Next k
  27.             sh.Cells(x, 10) = a  '合计:件数
  28.             sh.Cells(x, 11) = b  '合计:数量
  29.             MsgBox "您已向“入库”中加入了" & Z - 6 & "条记录,请在“入库”中进行确认!"
  30.         End If
  31.     End With
  32.     Application.ScreenUpdating = True
  33. End Sub
复制代码
回复

使用道具 举报

发表于 2015-11-19 14:56 | 显示全部楼层
再简洁一点,可以这样
  1. Sub 录入数据()
  2.     Dim sh As Worksheet
  3.     Application.ScreenUpdating = False
  4.     Set sh = Sheets("入库")
  5.     With Sheets("单据录入")
  6.         If .Range("J1") = "入库" Then
  7.             r = sh.[a65536].End(3).Row + 1   '入库表输入起始行
  8.             Z = .[c6].End(xlDown).Row      '当前表最大记录行
  9.             a = .Range("B:B").Find("合计").Offset(0, 2)     '合计:件数
  10.             b = .Range("B:B").Find("合计").Offset(0, 3)    '合计:数量
  11.             For k = 7 To Z
  12.                 x = r + k - 7
  13.                 sh.Cells(x, 1).Resize(1, 15) = Array(.Cells(5, 8), .Cells(4, 8), .Cells(k, 3), .Cells(k, 4), .Cells(k, 5), .Cells(k, 6), _
  14.                    .Cells(k, 7), .Cells(4, 2), .Cells(5, 2), , , .Cells(7, 10), .Cells(7, 11), .Cells(7, 12), .Cells(7, 13))
  15.             Next k
  16.             sh.Cells(x, 10) = a  '合计:件数
  17.             sh.Cells(x, 11) = b  '合计:数量
  18.             MsgBox "您已向“入库”中加入了" & Z - 6 & "条记录,请在“入库”中进行确认!"
  19.         End If
  20.     End With
  21.     Application.ScreenUpdating = True
  22. End Sub
复制代码
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-25 10:22 , Processed in 0.318428 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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