+ Reply to Thread
Results 1 to 7 of 7

How to divide 2 rows in VBA

  1. #1
    Registered User
    Join Date
    01-10-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Exclamation How to divide 2 rows in VBA

    I am working on a VBA code wherein I have to divide 2 rows in a particular worksheet...as of now I have a very primitive code which goes through each and every cell and performs the division using nested loops...but it is a time consuming process...

    So I was wondering if someone could help me with a simple code which directly divides the rows, that is:

    worksheet("test").row1 = worksheet("test").row2 / worksheet("test").row3

    Thanks in advance for all the help!!

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How to divide 2 rows in VBA

    Hi,

    How about

    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    01-10-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: How to divide 2 rows in VBA

    thanks for trying...but not working

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How to divide 2 rows in VBA

    Quote Originally Posted by amitgaja007 View Post
    thanks for trying...but not working
    In that case you'll need to upload a workbook so that we can see the problem in context. I'm assuming of course that you changed the A1:A3 refs. to match your actual data.

    Rgds

  5. #5
    Registered User
    Join Date
    01-10-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: How to divide 2 rows in VBA

    i have uploaded a simple example...i need to divide the 2 rows using a direct line of code in VBA...
    Attached Files Attached Files

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: How to divide 2 rows in VBA

    Here's one way:
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: How to divide 2 rows in VBA

    hi amitgaja007,

    In the comment you say "row3 = row1 / row2" & Shg's post will give you:
    "row3 = value in specific cell of row1 / value in specific cell of row2"

    However, my guess is that you want "row3 = sum of all cells in row1 / sum of all cells in row2", which will give the same value in every cell of row 3. Am I on the right track?

    Can you please try re-explaining your aim with the array formula?
    Please Login or Register  to view this content.
    I'm not sure if it will help as I don't understand what you need & I haven't used this before but vba has a "Range.FormulaArray Property" which may help you.

    Is this for a weighted average?
    Also, I'm curious, why do you want a vba solution?
    I'm sure that you could design a "template" style excel file that will work with just formulae.

    hth
    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

+ 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