Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Bastet Massri   on Jan 29 In MS Office Category.

  
Question Answered By: Fred Hicks   on Jan 29

Not without setting some sort of "flag" or indicator to say the code  has
been run  already.

You can do this in a number of ways.... But... You can also set up the code
in the auto_open procedure. This is run when the workbook is opened.

Option explicit

Sub Auto_Open
mln
End sub


Sub mln()

Dim llAnswer as long
Dim lsMsg as string
Dim lsTitle as string
Dim rlCell as Range

lsMsg = "Please note that this will replace  formulae with value."
lsMSg = lsMsg & vbCrLf
lsMSg = lsMsg & "So you are requested  to run this on a copy  of the file."

lsTitle = "Important"

llAnswer = MsgBox(lsMsg, vbYesNo + vbExclamation, lsTitle)

If llAnswer = vbYes Then

For Each rlCell In Selection

rlCell.Value = Application.WorksheetFunction.Round(c / 1000000, 2)

Next rlCell

End If

End Sub

Note too that I've "tidied" the code up a bit.

1) Put Option Explicit at the top.
This makes sure that code running undeclared variables will error.
2) Made more meaningful names of the variables.
3) Added Dim for the c / rlCell variable.
4) Added variables for the text strings.
This makes the msgbox code more "generic".
5) Structured the code to make it more readable.

Share: 

 

This Question has 6 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Messabe Box to appear once Or get search suggestion and latest updates.


Tagged: