2017-06-15 147 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

相关问题