Help with a short Macro

Dan Wilson

Well-known Member
Joined
Feb 5, 2006
Messages
546
Office Version
  1. 365
Platform
  1. Windows
Good day. I have a Macro that is working, but it needs one more step that I don't know how to do. The Macro below prints out either "Done" or "Failed" upon completion. When it prints out one of those words, the word is enclosed in a box labeled Microsoft Excel and it requires that I either select the "OK" button or hit the Return key to close it and move on. Is there a way to print out the words without having to follow up with another action? I appreciate any help with this.

VBA Code:
Sub Copy_Random_Numbers()
' 12/8/2024
' Copy_Random_Numbers Macro
' Copy random numbers and check for bad
'
Application.ScreenUpdating = falsemsg = "Sorry - failed"
For try = 1 To 3000
'
Range("a4:an4") = Range("a3:an3").Value
If Range("R14") = 0 Then
    msg = "Done"
    GoTo done
End If
Next try
Range("a6").Select
msg = "Failed"
'
done:
Application.ScreenUpdating = True
MsgBox msg
'
End Sub

Thank you,
Dan Wilson...
 
Last edited by a moderator:

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
By print I assume you mean your message box when it appears to remove the title then try...
VBA Code:
done:
Application.ScreenUpdating = True
MsgBox msg, , ""

If you mean a message box without a box then not as far as I know, there is code to get a messagebox to close after a set number of seconds (it isn't a normal msgbox, it is a Wscript Infobox)

P.S. please use code tags which might prevent lines like the below appearing in your posts plus makes your code easier to read and copy

Application.ScreenUpdating = falsemsg = "Sorry - failed"
 
Last edited:
Upvote 0
VBA Code:
Option Explicit


'The first part
#If Win64 Then '64?
    Private Declare PtrSafe Function MsgBoxTimeout _
        Lib "user32" _
        Alias "MessageBoxTimeoutA" ( _
            ByVal hwnd As LongPtr, _
            ByVal lpText As String, _
            ByVal lpCaption As String, _
            ByVal wType As VbMsgBoxStyle, _
            ByVal wlange As Long, _
            ByVal dwTimeout As Long) _
    As Long
#Else
    Private Declare Function MsgBoxTimeout _
        Lib "user32" _
        Alias "MessageBoxTimeoutA" ( _
            ByVal hwnd As Long, _
            ByVal lpText As String, _
            ByVal lpCaption As String, _
            ByVal wType As VbMsgBoxStyle, _
            ByVal wlange As Long, _
            ByVal dwTimeout As Long) _
    As Long
#End If

'The second part
Sub btnMsgbox()
    Call MsgBoxTimeout(0, "This message box will be closed after 4 seconds ", "Auto Close MsgBox", vbInformation, 0, 4000)  '<-- Adjusts view time here  > 4000 <
End Sub
 
Upvote 0
Good day Mark858 and thank you for responding. You made a good catch on "falsemsg = Sorry - Failed". I changed the falsemsg to false and all is well. I also discovered that the msg function is not necessary at all. There is a Cell on the Worksheet that shows the number of "Bad Counts" when the search is completed. If it comes up "0" the task is accomplished. If not, I will run the Macro again. You are correct that I should have used the word display instead of Print. I'm still fairly new at this. I appreciate the help. I have closed the post.
 
Upvote 0
Good day Logit and thank you for responding. I must admit, your response is way over my head. The more I look at it, the more I think I understand it. I will continue to work with it.
 
Upvote 0
@Dan Wilson
When posting vba code in the forum, please use the available code tags. It makes your code much easier to read/debug & copy. My signature block below has more details. I have added the tags for you this time. 😊
 
Upvote 0
@Dan Wilson
When posting vba code in the forum, please use the available code tags. It makes your code much easier to read/debug & copy. My signature block below has more details. I have added the tags for you this time. 😊

Good day Peter_SSs and it's good to hear from you again. I have no idea how to use the Code Tags. If you can point me in the right direction, I will comply.
Thank you,
Dan Wilson...
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,331
Members
452,907
Latest member
Roland Deschain

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