简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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