+ Reply to Thread
Results 1 to 5 of 5

Product (multiplication of cells)

Hybrid View

  1. #1
    Registered User
    Join Date
    04-10-2007
    Posts
    34

    Product (multiplication of cells)

    Hi,

    Hopefully this is an easy one...

    I'm looking to calculate the product of a nymber of consecutive cells in a particular row using VB.

    Example.

    I have, say, 5 variables listed in row 2 and I wish to find the product of these variables in cells B6 to B10 and produce the answer in cell B11

    i.e. cell B11 = B6*B7*B8*B9*B10

    In this example this is easy, however the problem is that I don't know how many variables I'll have, I only know the starting cell of the product will be in cell B(number of variables + 1) (e.g. B6 if 5 variables, B4 if 3 variables, etc.) and the answer will always be in cell B(2*number of variables + 1) (e.g. B11 if 5 variables, B7 if 3 variables).

    Can this be done with a simple command or will a loop be needed?

    Thanks,

    Mbrolass.

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,454
    Hi,

    Apologies if I'm missing your point here, but can't you use the worksheet function =PRODUCT()?
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Registered User
    Join Date
    04-10-2007
    Posts
    34
    I'm not actually doing the calculation in an excel spreadsheet and I've tried to find "product" in the visual basic commands but can not find it. I need to use it in a VB procedure and am not sure how.

    I'm new to VB so it may seem a silly question...

  4. #4
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,454
    Here ya go

    Sub mult()
    Dim answer As Single
    
    Range("A1:A3").Select
    answer = Application.WorksheetFunction.Product(UsedRange)
    Cells(1, 4).Value = answer
    End Sub

  5. #5
    Registered User
    Join Date
    04-10-2007
    Posts
    34
    That's great. Thanks

+ 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