Stem Step
Stem Step

Reputation: 71

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:

Before

Will turn into:

After

Upvotes: 0

Views: 1494

Answers (1)

Onmlock
Onmlock

Reputation: 63

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! :)

Upvotes: 3

Related Questions