+ Reply to Thread
Results 1 to 13 of 13

Button adding cells

  1. #1
    Registered User
    Join Date
    05-23-2013
    Location
    Poland
    MS-Off Ver
    Excel 2010
    Posts
    12

    Button adding cells

    Hello Everyone!

    I'm new here and I hope you will help me solve my problem

    First of all I think I should probably post this thread Excel Programming / VBA / Macros section but I'm not sure so I post it here

    Here is my problem. I have data in column A and some functions in column B. For exapmle:

    A B
    1 96 =A1*2+13
    2 84 =A2*2+13
    3 63 =A3*2+13
    4 47 =A4*2+13
    5 35 =A5*2+13

    Using functions Excel calculates results which are de facto numbers.

    Now I would like to create a button under the table that after clicking on it once would add all results from column B to resluts in column A (like A1+B1, A2+B2 and so on) so that new results of adding will be in column A.

    I supose I have to use macros and iterations to do this but I have no idea how to start. I have been searching on the Internet but I haven't been able to find the solution.

    Can someone help me here?

    EDIT: Thanks to administration for moving my thread to the correct section
    Last edited by fibonacci1101; 05-24-2013 at 12:45 PM. Reason: Thread moved to programming subforum.

  2. #2
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Button adding cells

    Try this -

    Please Login or Register  to view this content.
    I am assuming, you dont further need the Column B after its work is done.

    Thank You,

    Deep
    Attached Files Attached Files
    Last edited by NeedForExcel; 05-23-2013 at 02:26 PM.
    Cheers!
    Deep Dave

  3. #3
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Button adding cells

    Actually you dont really need to copy and paste the entire column here. However since the Macro isnt too complex and heavy Ive taken that approach.

    Try this -

    Please Login or Register  to view this content.
    Deep
    Last edited by NeedForExcel; 05-23-2013 at 02:28 PM.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Button adding cells

    Hi, fibonacci1101,

    maybe like this
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  5. #5
    Registered User
    Join Date
    05-23-2013
    Location
    Poland
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Button adding cells

    @msexcelathome, when I'm using your macro I'm getting error: Object required

    @HaHoBe, yours works fine
    But I have one more question. What if I would like to add different cells, let's say I would like to add cell G8 to C2, H8 to C3 and C11 to C4. How should I modified macro so I could change the cells however I want?

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Button adding cells

    Hi, fibonacci1101,

    use 2 arrays holding the addresses for the cells:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  7. #7
    Registered User
    Join Date
    05-23-2013
    Location
    Poland
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Button adding cells

    @HaHoBe, super! that's exactly what I needed! Is there anyway I can thank you? Any "Thanks" button on the forum? Cause I can't see it anywhere.

  8. #8
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Button adding cells

    Hi, fibonacci1101,

    glad if I was of any help.

    You could mark the thread as solved (either look at the Forum Rules for help on this or find the link in my signature) - and if any answer really has helped you might consider to click the star in that posting to add to the reputation of the person who posted that hint.

    Ciao,
    Holger

  9. #9
    Registered User
    Join Date
    05-23-2013
    Location
    Poland
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Button adding cells

    One more question. If I would like to add cells from, let's say, D6:D12 to C6:C12 (after clicking the button C6=C6+D6, C7=C7+D7 and so on). How should I modify this macro?

  10. #10
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Button adding cells

    Hi, fibonacci1101,

    the first code was for Column A to be added (giving 1 for the column number) so this could be altered to read:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  11. #11
    Registered User
    Join Date
    05-23-2013
    Location
    Poland
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Button adding cells

    Ok, thank you very much for explanation One last (I suppose) question If I would like to add cells from E13:E16 to cells from C5:C8 (like C5=C5+E13, C6=C6+E14 and so on) so that the spread between columns is bigger than one and I'm NOT adding neighbouring columns like before (A=A+B or C=C+D) but there is one or more columns between the cells I would like to add (C=C+E, but I'm leaving column D intact). And also I'm not adding the same rows like before (row 3 plus row 3, row 4 plus row 4 and so on) but different rows this time (row 5 plus row 13, row 6 plus row 14 and so on). How should I alter the macro?

  12. #12
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Button adding cells

    Hi, fibonacci1101,

    maybe you should have a read in the VBE Help about Offset which may be used for this request.

    Please Login or Register  to view this content.
    One last (I suppose) question
    The original question has long been answered, hasnīt it?

    Ciao,
    Holger

  13. #13
    Registered User
    Join Date
    05-23-2013
    Location
    Poland
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Button adding cells

    Ok, I've analysed your macro and I get it

    For lngCounter = 5 To 8; because I'm adding to rows from 5 to 8
    With Cells(lngCounter, 3); because I'm interested in cells in coulmn C which is 3rd column
    .Value = .Value + .Offset(8, 2).Value; because 13 = 5 + 8 (I'm adding rows starting from 13th row) and 5 = 3 + 2 (E is 5th coulmn)

    Now I understand As I said before it was my last question Original question has long been answered but I think there was no point in creating new thread Once again big thanks for helping me out, HaHoBe I'm marking this thread as "solved"
    Last edited by fibonacci1101; 05-24-2013 at 12:46 PM.

+ 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