简体   繁体   English

将原始数据复制到目标工作表的特定单元格中

[英]Copy raw data into specific cells of a target sheet

I have two worksheets within the same workbook, namely sheet1 ("rawdata") and sheet2 ("Overview).我在同一个工作簿中有两个工作表,即 sheet1(“原始数据”)和 sheet2(“概述”)。

I copy downloaded data into sheet1 ("rawdata").我将下载的数据复制到 sheet1(“原始数据”)中。 Here the number of rows vary but heading/columns are always the same.这里的行数有所不同,但标题/列始终相同。 After this I need to copy specific cells into another worksheet.在此之后,我需要将特定单元格复制到另一个工作表中。

Here are the "rules" I was thinking about:以下是我正在考虑的“规则”:

1) Always copy cells from the rawdata sheet E9, W9, X9 and Y9 into a specific cell in the target sheet. 1) 始终将原始数据表 E9、W9、X9 和 Y9 中的单元格复制到目标表中的特定单元格中。 I had something like this (which worked):我有这样的事情(有效):

Worksheets("overview").Range("X10").Value = Worksheets("rawdata").Range("E9").Value

2) Always copy the value within column E in the lastrow. 2) 始终复制最后一行 E 列中的值。 However, the last row is varying from rawdata to rawdata while the column (E) stays the same.但是,最后一行因原始数据而异,而列 (E) 保持不变。 I tried something like this: (not working)我试过这样的事情:(不工作)

....= Worksheets("rawdata").Range("E1").End(xlDown).Value

3) The script should be linked to the button, when I click the button again to insert the data from the sheet rawdata, the data should be inserted in the next (following) column of worksheet overview. 3)脚本应该链接到按钮,当我再次单击按钮从工作表原始数据中插入数据时,数据应该插入到工作表概述的下一(以下)列中。

Assumes column E always has data.假设列 E 总是有数据。 Which in this case should be true.在这种情况下应该是正确的。

Sorry tried to simplify and broke it.抱歉试图简化并破坏了它。

LastRow_WithDataInColumnE = Worksheets("rawdata").Range("E" & .Rows.Count).End(xlUp).Row

Should be应该

With Worksheets("rawdata")
    LastRow_WithDataInColumnE = .Range("E" & .Rows.Count).End(xlUp).Row
End With

Now .Rows.Count should refer to Worksheets("rawdata")现在 .Rows.Count 应该指的是 Worksheets("rawdata")

Worksheets("overview").Range("X10").Value = Worksheets("rawdata").Range("E" & .Rows.Count).End(xlUp).Row.Value

Should be应该

With Worksheets("rawdata")
    Worksheets("overview").Range("X10").Value = .Range("E" & .Rows.Count).End(xlUp).Row.Value
End With

There is a discussion here Error in finding last used cell in VBA .这里有一个讨论Error in find last used cell in VBA Suggests a better solution for situations where there is no data in Column E or where rows have been deleted.对于列 E 中没有数据或行已被删除的情况,建议更好的解决方案。

You could do something like this to get the last data range in column E:您可以执行以下操作来获取 E 列中的最后一个数据范围:

Public Function FindLastColumnECellAvailable()
    FindLastColumnECellAvailable = "E" & WorksheetFunction.CountA(Range("E:E"))
End Function

Then you will have this:然后你会有这个:

在此处输入图片说明

At the end just read the cell value:最后只读取单元格值:

Range(FindLastColumnECellAvailable).Value

在此处输入图片说明

Greetings你好

Sorry An apologize "in advance", I just read the date, hope this will help you yet or anyone else, it's my second day对不起,“提前”道歉,我刚看了日期,希望这对你或其他人有帮助,这是我的第二天

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

相关问题 将原始数据复制到目标工作表的特定单元格中 - Copying raw data into specific cells of a target sheet 根据行数据复制特定的单元格并粘贴在特定的工作表上 - Copy specific cells according to row data and paste on specific sheet 将特定的单元格复制到另一个工作表 - Copy specific cells to another sheet 如何在一张纸到另一张纸中的特定单元格的范围内复制单元格数据? - How do you copy cell data in a range from one sheet to specific cells in another sheet? 如何在不删除工作表2上的数据的情况下将单元格从工作表1复制到工作表2 - how to copy cells from sheet 1 to sheet 2 without removing data on sheet 2 根据条件将特定单元格从工作表复制到工作表 - Copy specific cells from sheet to sheet based on condition 将特定单元格从sheet2sheet复制到下一个空白行 - Copy Specific Cells from sheet2sheet to the next blank row 将过滤的数据复制到特定的工作表中 - Copy filtered data into specific sheet 如何根据工作表2中单元格的值从工作表1中复制特定单元格并将其粘贴到工作表2的相应行中? - How do I copy specific cells from sheet 1 and paste into corresponding rows of sheet 2 , based on values of cells in sheet 2? 将数据从工作表中的单元格复制到另一个工作表中的下一个可用行 - Copy data from cells in sheet to next available row in another sheet
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM