简体   繁体   English

Excel将数据复制到另一个工作表

[英]Excel Copying data to another sheet

Trying to do a worksheet for a Till Check, all data is entered manually, with that data then being copied to another sheet for future reference, now I have accomplished this bit (havn't coded in excel in yonks) However a little problem is it's copying that data multiple times, so instead of just 1 entry per row there's 5 rows with entered data. 尝试做一个“耕作检查”工作表,所有数据都是手动输入的,然后将这些数据复制到另一张表中以备将来参考,现在我已经完成了这一点(在yonks中没有用excel编码)。但是有一个小问题它会多次复制该数据,因此每行有5行,而不是每行只有1个条目。

A single row should have 5 different entries, Date, Cash Sales, Eftpos Sales, Totals, Checked By. 一行应有5个不同的条目,日期,现金销售,Eftpos销售,总计,检查者。

Sub Button2_Click()

  Dim rng As Range
  Dim i As Long
  Dim a As Long
  Dim rng_dest As Range
  Application.ScreenUpdating = False

  i = 1

  Set rng_dest = Sheets("Till Reports").Range("A:D")


  ' Find first empty row in columns D:G on sheet Invoice data

  Do Until WorksheetFunction.CountA(rng_dest.Rows(i)) = 0

    i = i + 1

  Loop


  Set rng = Sheets("Till Checks").Range("E21:F26")


  ' Copy rows containing values to sheet Till Checks


  For a = 1 To rng.Rows.Count


    If WorksheetFunction.CountA(rng.Rows(a)) <> 0 Then


      rng_dest.Rows(i).Value = rng.Rows(a).Value

      Sheets("Till Reports").Range("D" & i).Value = Sheets("Till Checks").Range("F24").Value
      Sheets("Till Reports").Range("A" & i).Value = Sheets("Till Checks").Range("E21").Value
      Sheets("Till Reports").Range("B" & i).Value = Sheets("Till Checks").Range("F22").Value
      Sheets("Till Reports").Range("C" & i).Value = Sheets("Till Checks").Range("F23").Value
      Sheets("Till Reports").Range("E" & i).Value = Sheets("Till Checks").Range("F25").Value

      i = i + 1

    End If

It is your For a = 1 To rng.Rows.Count . For a = 1 To rng.Rows.Count是您的。 Remove that and it should do it once. 删除它,它应该执行一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将Excel中的Excel数据复制到另一个工作表中 - Copying excel data from one sheet into another sheet 将数据复制到另一张纸上 - Copying data to another sheet 基于名称日期的 Excel 匹配并将数据复制到另一个工作表 - Excel matching based on name date and copying data to another sheet Excel VBA:扫描一张纸并将数据复制到另一张纸 - Excel VBA: scanning one sheet and copying data to another 将数据从列复制到另一个工作表-Excel上的VBA - Copying data from Column to another sheet - VBA on Excel 处理数据/复制到另一张纸 - Handling data/copying to another sheet 从另一张Excel工作簿复制数据-复制一张纸而不是一张纸 - Copying data from another excel workbook - instead of one sheet it's copying all of them 从一个工作表复制数据,然后将其粘贴到另一个Excel工作表时,Openpyxl边界线中断 - Openpyxl border line breaks when copying data from one sheet and then pasting it to another excel sheet 将在一张 Excel 中输入的某些数据复制/保存到另一张表并将其存储为数据库 - Copying/Saving certain data entered in one sheet of excel to another sheet and storing it as a database Excel宏,用于从一个工作表中的特定字段复制数据,仅保留该值并将其添加到另一工作表中 - Excel macro for copying data from a specific field in one sheet keeping only the value and adding it to another sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM