简体   繁体   English

VBA从另一个单元格中的工作表复制特定单元格

[英]VBA Copy a specific Cell from a sheet in an another cell

Here is my case 这是我的情况

I have this code in my Macro : The code is Good, no need to change it. 我的宏中有以下代码:该代码很好,无需更改。

Sheets("Water").Select
Cells.Select
Range("A2").Select
ActiveCell.Formula = "=SUM(D2:N2)+((COUNTIF(D2:N2,""GOLD"")+COUNTIF(D2:N2,""PLATIN""))*1)+((COUNTIF(D2:N2,""PLPLUS"")+COUNTIF(D2:N2,""AMBASS""))*2)"
Range("A2").AutoFill Destination:=Range("A2:A" & Cells(Rows.Count, 2).End(xlUp).Row)
LastRow = Range("A2").End(xlDown).Row
Cells(LastRow + 2, "A").Formula = "=SUM(A2:A" & LastRow & ")"
Dim LRowA As String, LRowB As String
LRowA = [A4200].End(xlUp).Address
Range("A:A").Interior.ColorIndex = xlNone
Range("A2:" & LRowA).Interior.ColorIndex = 33
Range("A:A").HorizontalAlignment = xlCenter

On this Code we are on Sheets "Water". 在此规范上,我们位于“水”表上。

I have a formula and the Result Appear here in the sheet "Water": 我有一个公式,结果出现在“水”表中:

 Cells(LastRow + 2, "A").Formula = "=SUM(A2:A" & LastRow & ")"

Now I want that this result appear on Sheet "Download" in the cell M8. 现在,我希望此结果出现在单元格M8的“工作表”中。

Is it possible..... 可能吗.....

Do you mean this? 你是这个意思吗 Have shortened your code a little too. 也缩短了您的代码。

Sub x()

Dim LRowA As String, LRowB As String

With Sheets("Water")
    .Range("A2:A" & .Cells(Rows.Count, 2).End(xlUp).Row).Formula = "=SUM(D2:N2)+((COUNTIF(D2:N2,""GOLD"")+COUNTIF(D2:N2,""PLATIN""))*1)+((COUNTIF(D2:N2,""PLPLUS"")+COUNTIF(D2:N2,""AMBASS""))*2)"
    LastRow = .Range("A2").End(xlDown).Row
    .Cells(LastRow + 2, "A").Formula = "=SUM(A2:A" & LastRow & ")"
    LRowA = .Range("A4200").End(xlUp).Address
    .Range("A:A").Interior.ColorIndex = xlNone
    .Range("A2:" & LRowA).Interior.ColorIndex = 33
    .Range("A:A").HorizontalAlignment = xlCenter
End With

Sheets("Download").Range("M8").Formula = "=""Bottle of water: "" & SUM(Water!A2:A" & LastRow & ")"

End Sub

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM