2017-08-08 39 views
-3

我有Excel中的表,並且想總結列「count」和「restocked」中的所有單元格,然後將結果覆蓋在列「count 「本身。接下來,宏將清除「補充」列中的所有現有值。excel vba - 總結表中的2列之間的行

將不勝感激任何幫助!

+4

我們不是代碼編寫服務。請告訴我們您已經擁有哪些代碼,哪些代碼失敗或需要改進。 – Luuklag

+0

請理解,人們在這裏幫助/協助您解決您的問題,而不是爲您完成工作併爲您編寫解決方案。所以一般來說,我們需要一些代碼,我們可以顯示哪些是錯誤的,以及在哪裏解決它。另請閱讀[如何問](https://stackoverflow.com/help/how-to-ask) – Moosli

回答

0

如上所述,我希望您在詢問您的下一個問題之前先研究一下。但我喜歡讓人們開始使用VBA的想法,所以這裏是:

Sub test() 
'First you dimension two variables as Ranges  
Dim cnt As Range 
Dim rstckd As Range 
'You assign the Ranges to the variable 
Set cnt = Range("A2:A4") 
Set rstckd = Range("B2:B4") 
'To store the results you initialize an array to store the sums 
Dim results() 
'You redimension the results array to the number of entries in your table 
ReDim results(1 To cnt.Rows.Count) 
'You loop over your table and sum the values from count and restocked 
For i = 1 To cnt.Rows.Count 
    results(i) = cnt(i, 1) + rstckd(i, 1) 
Next i 
'You write the array to the range count and delete the values in restocjed 
cnt = Application.Transpose(results) 
rstckd.Clear 

End Sub