+ Reply to Thread
Results 1 to 10 of 10

Help: Addition macro, Excel 2011

Hybrid View

  1. #1
    Registered User
    Join Date
    06-14-2013
    Location
    US
    MS-Off Ver
    Excel 2011
    Posts
    8

    Question Help: Addition macro, Excel 2011

    Need help with a macro that will
    Add the values of each cell in column A respectively to column B.

    I've tried
    Sub 1()
    Range("[Column 2]") = Range("[Column 2]") + Range("[Column 1]")
    End

    I am getting the following errors:
    Mismatch
    Method 'Range' of object'_Global' failed

  2. #2
    Forum Contributor
    Join Date
    02-28-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    272

    Re: Help: Addition macro, Excel 2011

    You can add substitute like, because in excel formulas also it will return to CIRCULAR REFFERENCE

    Sub 1()
    Range("[Column 3]") = Range("[Column 2]") + Range("[Column 1]")
    End
    Please consider adding a * if I helped

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Help: Addition macro, Excel 2011

    You can not add a range, but you can on individual cells. Try it in excel using columns A and B, it would not work.
    You need to use cells.

    Like

    Sub addme()
      With ActiveSheet
         .Cells(1, 3) = .Cells(1, 1) + .Cells(1, 2)
      End With
    End Sub
    Last edited by AB33; 06-14-2013 at 12:40 PM.

  4. #4
    Registered User
    Join Date
    06-14-2013
    Location
    US
    MS-Off Ver
    Excel 2011
    Posts
    8

    Re: Help: Addition macro, Excel 2011

    Any way I can write it to repeat the action for each cell in the column then?

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Help: Addition macro, Excel 2011

    Wfm,

    You can not have a sub name which commence with a number.
    You need to have
    End Sub, Not just end

  6. #6
    Forum Contributor
    Join Date
    02-28-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    272

    Re: Help: Addition macro, Excel 2011

    Use this
    Sub Auto()
        Range("A2:A1048576").Select
        Selection.Copy
    CutCopyMode = False
        Range("B2:B1048576").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd, SkipBlanks _
            :=False, Transpose:=False
    
    End Sub

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Help: Addition macro, Excel 2011

    Cronen,
    Yes, you have to loop through each row.
    You need to highlight the range, or select range then when you paste, you need to select paste special and add.
    You can use recoded macro if you struggle, or excel function

  8. #8
    Registered User
    Join Date
    06-14-2013
    Location
    US
    MS-Off Ver
    Excel 2011
    Posts
    8

    Re: Help: Addition macro, Excel 2011

    Ok, heres what I got (and thanks again you two!)
    "
    Sub add()
    Range("Accounting!B2:B142").Select
    Selection.Copy
    CutCopyMode = False
    Range("Inventory List!G5:G145").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd, SkipBlanks _
    :=False, Transpose:=False

    End Sub
    "
    Now getting the Method 'Range' of object'_Global' failed error.

    I tried the original code and it works exactly how I want. Now just to finish this last bug.

  9. #9
    Registered User
    Join Date
    06-14-2013
    Location
    US
    MS-Off Ver
    Excel 2011
    Posts
    8

    Re: Help: Addition macro, Excel 2011

    Tried it on the same Sheet, seems like its working now. Thanks you two!

  10. #10
    Forum Contributor
    Join Date
    02-28-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    272

    Re: Help: Addition macro, Excel 2011

    Use this one
    Sub add()
    Sheets("Accounting").Activate
        Range("B2:B142").Select
        Selection.Copy
    CutCopyMode = False
    Sheets("Inventory List").Activate
        Range("G5:G145").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd, SkipBlanks _
            :=False, Transpose:=False
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1