none
VBA Multiplication Loop RRS feed

  • Question

  • Hi, 

    I had a question about a multiplication problem that requires loop. 

    I have a button that allows users to insert information and my app needs to give a calculation as an output. I need a formula to be able to multiply cells A1*A2*A3*7.85 but as users insert more information, it would need to go down to B1*B2*B3*7.85 ... 

    I tried to do i = 0 and loop as it would be i+1 but cant seem to get it to work. 

    Mainly the formula that I have is not working. 

    If anyone could help that would be great ! 

    Thank you, 

    Mariam A


    • Edited by Mariam Abd Saturday, April 14, 2018 7:36 PM
    Saturday, April 14, 2018 7:34 PM

All replies

  • Mariam
    re:  multiple 3 columns

    Maybe...
    The following code finds the last row in column 3 and multiplies the first 3 cells in that row.
    '---
    Sub MultipleThreeColumns()
     Dim LastRow As Long
     Dim dblTotal As Double
     
     LastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, 3).End(xlUp).Row
     dblTotal = ActiveSheet.Cells(LastRow, 1).Value2 * _
     ActiveSheet.Cells(LastRow, 2).Value2 * ActiveSheet.Cells(LastRow, 3).Value2
     ActiveSheet.Cells(LastRow, 4).Value2 = dblTotal
    End Sub
    '---
    Jim Cone
    https://goo.gl/IUQUN2
    Sunday, April 15, 2018 2:32 AM
  •  

    Hello Mariam Abod,

    >>I need a formula to be able to multiply cells A1*A2*A3*7.85 but as users insert more information, it would need to go down to B1*B2*B3*7.85 ... 

    How does user insert information? Why you need go down to B1*B2*B3*7.85? Where would you output the result?

    Would you mind share a sample screenshot that illustrates the desired result or behavior.

    For sharing file, you could share the file via Cloud Storage, such as One Drive, and then put link address here. Thanks for understanding.

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 16, 2018 7:16 AM