Solved

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

Posted on 2014-01-20
4
476 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 47

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

730 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