Solved

VBA Excel Statement     NM = MsgBox("Data has been clear", vbOKOnly, "New Month")

Posted on 2014-01-20
4
472 Views
Last Modified: 2014-01-20
See

NM = MsgBox("Data has been clear", vbOKOnly, "New Month")

What does this mean?  I understand the bit to the right of the "=".

What does the bit to the left mean?

The NM (presumably "New Month") is never referred to again else where.
What purpose does it serve (since never referred to again)


Sub NewMonth()
    Application.ScreenUpdating = False
    Sheet48.Select
    Range("GoTo1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Range(Selection, Selection.End(xlToLeft)).Select
    Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    Range("A1").Select
    Sheet38.Select
    Range("EvaDailyData").Select
    Selection.ClearContents
    Range("A1").Select
    Sheet29.Select
    Application.ScreenUpdating = True
    NM = MsgBox("Data has been clear", vbOKOnly, "New Month")
End Sub
0
Comment
Question by:Patrick O'Dea
  • 2
4 Comments
 
LVL 24

Accepted Solution

by:
Steve earned 500 total points
ID: 39793601
As you are using the vbOKOnly in the messagebox VBA is expecting a response of some kind to the messagebox question "is it OK".
So if you try the following you will see it wants a response, as it will error saying "expected =".

Sub test()
    MsgBox("Data has been clear", vbOKOnly, "New Month")
End Sub

Open in new window


The NM is just there to fulfill that requirement... it does nothing else and can be anything really.
0
 

Author Closing Comment

by:Patrick O'Dea
ID: 39793609
Ahhh!  Easym thanks!
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 39794454
Since you have already accepted an answer to this question I obviously don't expect any points but I feel I should make a couple of comments.

1) While as Steve pointed out MsgBox("Data has been clear", vbOKOnly, "New Month") will give you an error, MsgBox "Data has been clear", vbOKOnly, "New Month" won't. That's because the former is calling the MsgBox function expecting a return value, while the latter doesn't.

2) When you want to know what the user's response is you can do something like this.

NM = MsgBox("Do you want to clear the data?", vbYesNo, "New Month")
If NM = vbNo Then 
    Exit Sub
Else
    ' Clear the data
End If

Open in new window

0
 

Author Comment

by:Patrick O'Dea
ID: 39795300
Thank ML .... Some day that will be useful!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now