Solved

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

Posted on 2014-01-20
4
474 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 46

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Office 2016 without internet 6 38
Excel formula Sumif not working 4 28
VBA Works in Excel 2010 Not 2016 Help! 5 19
Excel Charts: How is this Chart made? 8 28
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

773 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