Excel精英培训网

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

[已解决]求助,代码有问题,自己找不出错误。请各位老师帮助解决,谢谢啦!

[复制链接]
发表于 2012-1-16 09:09 | 显示全部楼层 |阅读模式
每次录入后会多1行内容,知道原因,但不知道怎么改正,求帮助,谢谢各位老师了。 求助.rar (20.28 KB, 下载次数: 17)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2012-1-16 09:49 | 显示全部楼层
  1. Sub aa()
  2.     Dim arr, arr1, i As Long, n As Long
  3.     Dim str1 As String, str2 As String, date1 As Date
  4.     arr = Range("D9:M14")
  5.     ReDim arr1(1 To UBound(arr), 1 To UBound(arr, 2) + 3)
  6.     str1 = [E6]
  7.     str2 = [L5]
  8.     date1 = [L6]
  9.     For i = 1 To UBound(arr)
  10.         If arr(i, 1) = "" Then
  11.             With Sheets("军")
  12.             n = .[A65536].End(xlUp).Row + 1
  13.             .Range("A" & n).Resize(UBound(arr1), UBound(arr1, 2)) = arr1
  14.             End With
  15.             MsgBox "数据录入完成"
  16.             Range("D9:M14").ClearContents
  17.             Exit Sub
  18.         Else
  19.             arr1(i, 1) = str1
  20.             arr1(i, 2) = date1
  21.             arr1(i, 3) = str2
  22.             For j = 4 To UBound(arr1, 2)
  23.                 arr1(i, j) = arr(i, j - 3)
  24.             Next j
  25.         End If
  26.     Next i
  27. End Sub
复制代码
回复

使用道具 举报

发表于 2012-1-16 09:50 | 显示全部楼层    本楼为最佳答案   
附件: 求助-sunjing.rar (23.12 KB, 下载次数: 11)
回复

使用道具 举报

发表于 2012-1-16 09:51 | 显示全部楼层
  1. Sub 录入()
  2. Dim index As Integer
  3. Dim ws As Worksheet
  4. Dim rng As Range
  5. If Application.WorksheetFunction.CountIf(Worksheets("军").Range("A:A"), Range("E6")) > 0 Then
  6.    MsgBox "此单号已录入过,不能重新录入", , "操作提示"
  7. Exit Sub
  8. End If
  9. Set ws = Worksheets("军")
  10. For Each rng In Range("D9:D14")
  11.     If rng.Value <> "" Then
  12.        index = ws.UsedRange.Rows.Count + 1
  13.        With ws
  14.           .Range("a" & index).Value = Range("E6")
  15.           .Range("b" & index).Value = Format(Range("L6"), "mm-dd-yy")
  16.           .Range("c" & index).Value = Range("L5")
  17.           For mcol = 4 To 13
  18.             .Cells(index, mcol) = Cells(9, mcol)
  19.           Next
  20.       End With
  21. End If
  22. Next
  23. MsgBox "录入完毕", , "操作提示"
  24. Range("E6,L5,L6,D9:M14") = ""
  25. End Sub
复制代码

回复

使用道具 举报

 楼主| 发表于 2012-1-16 10:54 | 显示全部楼层
谢谢各位老师的帮助,我去试试。
回复

使用道具 举报

发表于 2012-1-29 10:18 | 显示全部楼层
高手                                                  
回复

使用道具 举报

发表于 2012-7-10 14:24 | 显示全部楼层
都是高手,加油         
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-17 01:44 , Processed in 0.209046 second(s), 12 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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