+ Reply to Thread
Results 1 to 7 of 7

Divide a range of cells then add up the number and paste value with VBA.

  1. #1
    Forum Contributor
    Join Date
    07-01-2010
    Location
    Niles, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    137

    Divide a range of cells then add up the number and paste value with VBA.

    Could someone help me with creating a VBA code to do the following
    Cell H8 will be where I need the value to be placed.
    If there's a number value in Range D68:D81 and there's a number value in range H68:H81 I would like to divide H68 by D68 and put that number in cell H8. And on down the rows.
    So say H68 is 300 and D68 is 2 then cell H8 would show 150.
    And if H80 is 400 and D80 is 2 then cell H8 would 350. It would add up the values and put that number in cell H8.

    Thanks in advance
    Excel 2010

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Divide a range of cells then add up the number and paste value with VBA.

    Please Login or Register  to view this content.
    If you are happy with my response please click the * in the lower left of my post.

  3. #3
    Forum Contributor
    Join Date
    07-01-2010
    Location
    Niles, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: Divide a range of cells then add up the number and paste value with VBA.

    I'm getting a Run-time error '28':
    Out of stack Space

    Please Login or Register  to view this content.
    Do you know what I'm doing wrong with it?

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Divide a range of cells then add up the number and paste value with VBA.

    Try
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    07-01-2010
    Location
    Niles, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: Divide a range of cells then add up the number and paste value with VBA.

    That seems to be working better. It's doing some calculations but if I type 2 in cell D68 and type in 200 in cell H68 the result in cell H8 shows 0.01. And it should show 100. I might be missing something here but it's close. Any ideas?

  6. #6
    Forum Contributor
    Join Date
    07-01-2010
    Location
    Niles, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: Divide a range of cells then add up the number and paste value with VBA.

    Nevermind. I had the D column getting divided by the H column. And I needed it the other way. So thank you very much!!

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Divide a range of cells then add up the number and paste value with VBA.

    You are welcome and thanks for the rep.

    It is using formula to calculate, so if you enter formula
    =sum(if((isnumber(d68:d81))*(isnumber(h68:h81)),d68:d81/h68:h81))
    in H8 and confirm with Ctrl+Shift+Enter (array forumla entry), it should update automatically.
    So no need of vba.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Looking to paste a word over a range cells and add a number at the end.
    By NWR1Games in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 11-21-2014, 02:29 PM
  2. Replies: 13
    Last Post: 11-19-2014, 11:22 AM
  3. Copy range and paste as value and clearcontants of blank cells and number
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-12-2014, 06:59 AM
  4. Amending formula to divide by the first number in the range used.
    By joshnathan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-15-2012, 09:38 AM
  5. Replies: 5
    Last Post: 07-16-2010, 01:45 PM
  6. Divide only with number of cells with value>0
    By primaxx in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-27-2009, 03:39 AM
  7. divide all numbers in range by a fixed number
    By dhig3903 in forum Excel General
    Replies: 2
    Last Post: 08-09-2006, 03:10 AM

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