Compile error with VBA MsgBox

bbbb1234

Board Regular
Joined
Aug 8, 2002
Messages
150
Office Version
  1. 365
Platform
  1. Windows
When I put this VERY long line for a message box in VBA, it compiles fine:
If MsgBox("NOTE: If the cursor is in a cell where the line will be deleted, the cursor will be positioned around row 500 after the macro finishes. You can click OK and manually scroll up after the macros completes or click Cancel to reposition the cursor and restart this macro." & Chr(10) & Chr(10) & "Click " & Chr(34) & "Cancel" & Chr(34) & " to skip the macro and reposition the cursor manually before restarting the macro" & Chr(10) & "Click " & Chr(34) & "OK" & Chr(34) & " to proceed with macro execution and scroll up after the macro completes.", vbOKCancel + vbExclamation + vbApplicationModal, "INFORMATION") = vbCancel Then Exit Sub

But when I shorten it up using the _ character to indicate the line continues, like this:
If MsgBox("NOTE: If the cursor is in a cell where the line will be deleted, the cursor will be positioned " _
"around row 500 after the macro finishes. You can click OK and manually scroll up after the macros " _
"completes or click Cancel to reposition the cursor and restart this macro." & Chr(10) & Chr(10) & _
"Click " & Chr(34) & "Cancel" & Chr(34) & " to skip the macro and reposition the " _
"cursor manually before restarting the macro" & Chr(10) & "Click " & Chr(34) + _
& "OK" & Chr(34) & " to proceed with macro execution and scroll up after the macro completes.", _
vbOKCancel + vbExclamation + vbApplicationModal, "INFORMATION") = vbCancel Then Exit Sub

I get this compile error, "Expected: list separator or )"

What am I doing wrong???
 
Last edited:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Nevermind on this request!! It took me a while but I finally figured it out and was able to fix the compile error as follows:
If MsgBox("NOTE: If the cursor is in a cell where the line will be deleted, the cursor will be positioned " & _
"around row 500 after the macro finishes. You can click OK and manually scroll up after the macros " & _
"completes or click Cancel to reposition the cursor and restart this macro." & Chr(10) & Chr(10) & _
"Click " & Chr(34) & "Cancel" & Chr(34) & " to skip the macro and reposition the " & _
"cursor manually before restarting the macro" & Chr(10) & "Click " & Chr(34) + _
"OK" & Chr(34) & " to proceed with macro execution and scroll up after the macro completes.", _
vbOKCancel + vbExclamation + vbApplicationModal, "INFORMATION") = vbCancel Then Exit Sub

Thanks to all who read my post!!
 
Upvote 0
You might find it easier to read and trouble shoot if you do something like this:
PS: If you use the VBA button to post your code it is also easier for us to read the code you post.

VBA Code:
Sub testMsg()

Dim msgText As String

msgText = "NOTE: If the cursor is in a cell where the line will be deleted, the cursor will be positioned " & _
            "around row 500 after the macro finishes. You can click OK and manually scroll up after the macros " & _
            "completes or click Cancel to reposition the cursor and restart this macro." & Chr(10) & Chr(10) & _
            "Click " & Chr(34) & "Cancel" & Chr(34) & " to skip the macro and reposition the " & _
            "cursor manually before restarting the macro" & Chr(10) & "Click " & Chr(34) + _
            "OK" & Chr(34) & " to proceed with macro execution and scroll up after the macro completes."

If MsgBox(prompt:=msgText, Buttons:=vbOKCancel + vbExclamation + vbApplicationModal, Title:="INFORMATION") = vbCancel Then Exit Sub

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,316
Members
452,634
Latest member
cpostell

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