2017-03-08 119 views
0

這裏是我的情況VBA複製從紙張的特定細胞在另一個細胞

我有這樣的代碼在我的宏:該代碼是良好的,沒有必要去改變它。

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 

關於此代碼,我們在表「水」。

我有一個公式和結果在片「水」出現在這裏:

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

現在我想,這導致細胞M8上表顯示「下載」。

是否有可能.....

回答

1

你的意思是?縮短了你的代碼。

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 
+0

PERFECTO,只有一個小東西我想提出「一瓶水:」在前面....是有可能 – JohanEs

+0

見修改代碼。 – SJR

+1

你能告訴我,如果這有效嗎? – SJR