+ Reply to Thread
Results 1 to 4 of 4

Division of two columns across multiple rows

  1. #1
    Registered User
    Join Date
    09-05-2012
    Location
    Bellingham, WA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Division of two columns across multiple rows

    Hi-
    I've been trying to modify the code found here: http://www.excelforum.com/excel-prog...other-set.html but can't seem to figure it out, and as a lot of people have said, I'm new to macros. I need to take column E and divide it by column C for each row. The final product would look like this in long hand:
    =(1/69)*((E4/C4)+(E5/C5)+(E6/C6)+(E7/C7).... (E72/C72))*100.
    In the attached spreadsheet, the macro would be working on "By prey item" sheet, but the result needs to go on "Fish Techniques Results" in the percent by weight column. This will need to get rerun for each prey item (Diptera, Amphipoda etc) and for both percent by weight and numbers (column E for Diptera in By Prey Item and going in Column C on Fish Techniques). Hope that all makes sense.

    Also, does anyone have any suggestions for a good text book to get deeper into Macros? I have not perused the forum extensively for this answer.

    Thanks for your help.
    Attached Files Attached Files
    Last edited by WiscoEm; 11-07-2013 at 02:03 AM.

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

    Re: Division of two columns across multiple rows

    I am not sure if the attached what you want. You have not attached a desired output sheet.
    You have merged cells. The code would not work with merged cells.
    I assumed that you have fixed columns for weight (E) and number (C).
    I was unable to touch any part of the book as you have lots of lined formula.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    09-05-2012
    Location
    Bellingham, WA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Division of two columns across multiple rows

    Thanks AB33-
    That works. I'll remember in the future to include a desired output sheet. Does VBA never work with merged cells? Also, can you explain to me what the ReDim line is saying/doing?

    I really appreciate your help.

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

    Re: Division of two columns across multiple rows

    ReDim
    In plain English means "Resize" of the array.
    If you have look at the code, I have commented cells(In green). The output could have written directly in to range(sheet), instead of first copying in to the resize array(Z). If you uncommented these two green lines, when the code finishes each row, the result will be copied one at a time, but with redim statement, the code writes back in to the range once it finishes lopping through the rows. The advantage of the redim is to speed the execution of the code, which may be the factor if you have large data.

    Merged cells and VBA are not good friends.
    When you merge cells, two cells are merged in to one. And when a code loops through the merged cells, it will not find which of the cells the code is referring to. It is highly likely you will get an error, or unexpected result. So avoid, merging cells
    Last edited by AB33; 11-07-2013 at 03:53 PM.

+ 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. Combining multiple rows from 2 columns into sorted columns depending on 1st columns value
    By Dexamphetamine in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-11-2013, 10:00 AM
  2. Multiple ccolums/rows to get data from multiple columns/rows (vlookup)
    By Ramzes in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-18-2010, 05:35 AM
  3. Replies: 1
    Last Post: 05-18-2009, 11:21 AM
  4. Replies: 1
    Last Post: 03-18-2009, 04:18 PM
  5. Replies: 0
    Last Post: 07-31-2006, 12:13 PM

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