[英]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.