Results 1 to 4 of 4

Thread: VBA subtract from next column above cell
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Feb 2018
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default VBA subtract from next column above cell

    A B c
    5000
    1 300 4700
    2 500 4200
    3 600 3600

    Hi Team,
    I have a sheet like above.

    I need to subtract B2 from c1, B3 from C2, B4 from C3 till last row of B.

    Need a vba code. Can some one help me on this.

  2. #2
    MrExcel MVP
    Junior Admin
    Joe4's Avatar
    Join Date
    Aug 2002
    Posts
    50,731
    Post Thanks / Like
    Mentioned
    57 Post(s)
    Tagged
    11 Thread(s)

    Default Re: VBA subtract from next column above cell

    Try this:
    Code:
    Sub MyMacro()
    
        Dim lr As Long
        
    '   Find last row in column B with data
        lr = Cells(Rows.Count, "B").End(xlUp).Row
        
    '   Populate column C with formulas, starting on row 2, going down to last row
        Range("C2:C" & lr).FormulaR1C1 = "=R[-1]C-RC[-1]"
    
    End Sub
    TIPS FOR FINDING EXCEL SOLUTIONS
    1. Use the built-in Help that comes with Excel/Access
    2. Use the Search functionality on this board
    3. A lot of VBA code can be acquired by using the Macro Recorder.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for life!"

  3. #3
    New Member
    Join Date
    Feb 2018
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA subtract from next column above cell

    Thanks MrExcel MVP,

    Great Stuff...Expected result came out

  4. #4
    MrExcel MVP
    Junior Admin
    Joe4's Avatar
    Join Date
    Aug 2002
    Posts
    50,731
    Post Thanks / Like
    Mentioned
    57 Post(s)
    Tagged
    11 Thread(s)

    Default Re: VBA subtract from next column above cell

    You are welcome.
    TIPS FOR FINDING EXCEL SOLUTIONS
    1. Use the built-in Help that comes with Excel/Access
    2. Use the Search functionality on this board
    3. A lot of VBA code can be acquired by using the Macro Recorder.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for life!"

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •