2017-06-15 148 views
0

我需要一個將「未分類」列中的值添加到「公司」中的VBA宏。使用Excel VBA宏將一列中的值添加到另一列

我不能用公式來做這件事,因爲我必須在之後完全刪除Unclassified列。

例如:

Before

會變成:

After

+0

爲什麼不只是使用列O作爲輔助列,在其中放置SUM()公式,然後將這些值複製/粘貼到「公司」中,然後可以刪除該列。 ...不需要VBA。 – BruceWayne

回答

2

讓我知道,如果這個工程

Sub CorporateAdd() 
    Application.ScreenUpdating = False 

    Dim TotalRows As Long 
    Dim UnclassArray As Variant, CorporateArray As Variant 
    TotalRows = Range("L1048576").End(xlUp).Row 

    UnclassArray = Columns("N") 
    CorporateArray = Columns("L") 

    For i = 4 To TotalRows 
     CorporateArray(i, 1) = CorporateArray(i, 1) + UnclassArray(i, 1) 
    Next i 

    Columns("L") = CorporateArray 

    'Uncomment this if you want it to automatically delete "Unclassified" 
    'Columns("N").Delete Shift:=xlLeft 

    Application.ScreenUpdating = True 
End Sub 

但對於未來的參考,我不當你問的時候,你就不會想人對於代碼,請先嚐試一下自己,如果它不起作用,請到這裏尋求修復它的幫助! :)

+0

啊,是的,我忘了我的禮貌。感謝您的幫助。 –

+0

沒什麼大不了的! :) – Dexloft

相關問題