• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

program to compute summultiple

ademilola

New Member
Good day, guys I need your help, in writing a program on how to compute the sum and product of multiple of 5 within the range of 1-23 using excel vba
 
Try these two solutions

Code:
Sub Ans1()

Dim Base As Double
Dim top As Integer

Base = 5
top = 23

For i = 1 To top
  Title = "Sum & Product"
  prompt = "The Sum of " + CStr(i) + " and " + CStr(Base) + " = " + CStr(i + Base)
  prompt = prompt + Chr(10)
  prompt = prompt + "The Product of " + CStr(i) + " and " + CStr(Base) + " = " + CStr(i * Base)
 
  MsgBox prompt, vbOKOnly, Title
Next i

End Sub

This will return a dialog like:
upload_2017-10-26_22-23-49.png


Code:
Sub Ans2()

Dim Base As Double
Dim top As Integer

Base = 5
top = 23

Debug.Print "i", "i + " + CStr(Base), "i * " + CStr(Base)
Debug.Print "==========", "==========", "=========="
For i = 1 To top
  Debug.Print i, i + Base, i * Base
Next i

End Sub

This will return the
upload_2017-10-26_22-24-28.png

Copy each piece of code into VBA and press F5
 
If you want the results in a worksheet?

Code:
Sub Ans3()

Dim Base As Double
Dim top As Integer

Base = 5
top = 23

Range("A1") = "i"
Range("B1") = "i + " + CStr(Base)
Range("C1") = "i * " + CStr(Base)
Range("A2") = "'======="
Range("B2") = "'======="
Range("C2") = "'======="

For i = 1 To top
  Cells(2 + i, 1) = i
  Cells(2 + i, 2) = i + Base
  Cells(2 + i, 3) = i * Base
Next i

End Sub

will produce

upload_2017-10-26_22-30-51.png
 
Back
Top