Needs Help With A MessageBox

Hi everyone :)

I am trying to make a VBA that will display a message box that will show me the numbers between 0 and 100 that are divisible by 8 AND is a multiple of 7.

Any help is much aprreciated!
LVL 4
An Average Forum Participant Just For FunHardware Tester and DebuggerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fabrice LambertFabrice LambertCommented:
Try the following:
Public Sub test()
    Dim message As String
    Dim number As Integer
    For number = 0 To 100
        If (number Mod 8) = 0 And (number Mod 7) = 0 Then
            message = message & number & " "
        End If
    Next
    MsgBox "The following numbers are divisible by 8 and multiple of 7:" & vbCrLf & message, vbOKOnly + vbInformation, "Result"
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Martin LissOlder than dirtCommented:
You should change Fabrice's line 4 to For number = 1 To 100 because otherwise one of the results is zero and that obviously doesn't fit the requirements. Also note that "divisible by" (assuming evenly) and "multiple of" are the same thing, so the message wording could be changed to

"The following numbers are evenly divisible by 8 and 7"
0
Martin LissOlder than dirtCommented:
Another way of doing it is:

Public Sub test()
    Dim message As String
    Dim number As Integer
    For number = 1 To 100
        If number Mod (8 * 7) = 0 Then
            message = message & number & " "
        End If
    Next
    MsgBox "The following numbers are divisible by 8 and multiple of 7:" & vbCrLf & message, vbOKOnly + vbInformation, "Result"
End Sub

Open in new window

0
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

hnasrCommented:
To understand the question, try to show the required result manually.
0
An Average Forum Participant Just For FunHardware Tester and DebuggerAuthor Commented:
Hi everyone!

Below is how I would prepare my code, however, I am not sure if it can display multiple answers
1.JPG
Can anyone help me edit it so it can show all the answers if there is more than one value?

This is because I do not know what this code here does from one of the solutions provided above:
& vbCrLf & message, vbOKOnly + vbInformation, "Result"
0
Martin LissOlder than dirtCommented:
With 7 and 8 there is only one answer between 1 and 100, 56 which is 1*7*8. If your range was larger the next number would be 2*7*8 or 112, etc.
0
Martin LissOlder than dirtCommented:
Here's an article that explains how to use a msgbox.
0
An Average Forum Participant Just For FunHardware Tester and DebuggerAuthor Commented:
Alright thank you very much! :)
0
Martin LissOlder than dirtCommented:
I see that my comments weren't worth anything to you. Oh well.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.