简体   繁体   中英

Use Excel VBA Macro to Add values from one Column to another

I need a VBA macro that adds the values in column "Unclassified" into "Corporate."

I cannot do this with a Formula because I must delete the column Unclassified completely afterwards.

For example:

之前

Will turn into:

后

let me know if this works

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

But for future reference, I don't think people like when you ask for code, try it out yourself first and if it doesn't work come here for help on fixing it! :)

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