English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Im trying to display cell b3 in a message box.

So far i got:
MsgBox "The answer is "....Now i want to display cell b3 but i cant. Please help!

2007-12-11 11:03:57 · 3 answers · asked by basics_87 1 in Computers & Internet Software

I forgot to mention that the cell is in a sheet called Data.

2007-12-11 11:26:31 · update #1

3 answers

You do it like this:

MsgBox ("The answer is " & _
Worksheets("Data").Range("B3").Value & ".")

However, I would recommend naming the range, then using that to reference the cell in your macro. For example, you could call the cell "MyAnswer", then write the following for your macro.

MsgBox ("The answer is " & _
Range("MyAnswer").Value & ".")

The space followed by an underscore represents a line continuation for a line of code. It tells the computer to accept the following line of cone as if it was part of that line of code.

To name the cell, select the cell then go up to the Name Box which is just above cell A1. It should state B3 in the Name Box if you have cell B3 selected. Put your cursor in the Name Box and type in MyAnswer and then hit the enter button. You will have just named cell B3 on the Data worksheet as MyAnswer. You will no longer need to specify the worksheet because that name refers to that cell range wherever that cell range is in the workbook. And if someone decides to insert a row or column that moves the contents in cell B3, because the cell range is named the macro will follow the cell range to wherever it moves to. If you use the absolute cell reference of just B3 it won't move along with the data it will return whatever is in cell B3 no matter what. It also will allow the macro to reference that data even if someone changes the worksheet name. If you don't name the range, then when somebody changes the name of the worksheet, the macro will no longer work.

2007-12-12 03:29:18 · answer #1 · answered by devilishblueyes 7 · 0 0

Excel Macro Message Box

2016-11-07 05:47:10 · answer #2 · answered by ritzer 4 · 0 0

If cell is A1001 do this as a macro

Msgbox "here is the current value of cell" & Worksheets("Data").Range("A1001")

2007-12-11 13:36:13 · answer #3 · answered by Trev 6 · 0 2

fedest.com, questions and answers