Need help writing a VBA function that prints a loop

pab88

New Member
Joined
Oct 17, 2017
Messages
1
Hi everyone,
I am messing around with Excel and as an assignment I need to create a VBA function that prints my name 10 times in a loop. Then I need to create a button that will trigger the function. How can I do this?

I tried:

Module Hello
Sub Main()
MsgBox ("Hi, my name is Pat")
End Sub
End Module

But it did not work. I am not sure how to get the button to work either. If you could offer any help I would really appreciate it. thank you!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Welcome to the board.

For the code, try:
Code:
Sub Main()

    Dim x   As Long
    
    Application.ScreenUpdating = False
    
    For x = 1 To 10
        Cells(x, 1).Value = "Hi, my name is Pat"
    Next x
    
    Application.ScreenUpdating = True

End Sub
You can search online on how to attach a macro to a button: http://tinyurl.com/y8426jmz
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top