Using ActiveCell to display cell value in MsgBox

Darren_workforce

Board Regular
Joined
Oct 13, 2022
Messages
146
Office Version
  1. 365
Platform
  1. Windows
Hello,

Is it possible with VBA to generate a Message Box that displays the cell data anytime a cell is clicked on without having to re-run the macro each time? I know you have to click on 'OK' to clear the message box but then after that, when the mouse is clicked into a different cell, can the cell data automatically generate within a new MsgBox? Or is that asking too much of VBA?

Regarding the actual Msg Box popup, is it able to generate the MsgBox without the 'OK' button? Allow the MsgBox to appear but then automatically after XX seconds, the MsgBox would just go away.

VBA Code:
MsgBox ActiveCell.Text


EDIT:
I found this on the MS site but am not certain how to reference it to an active cell so the data would automatically be displayed.

VBA Code:
CreateObject("WScript.Shell").PopUp "Your Message", 5
 
Last edited by a moderator:

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Oh I think I found something helpful and inserted into the worksheet I need it in. But can it be linked to my second question regarding the time to display and automatically disappearing after said time?

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    With ActiveCell
        MsgBox .Value & "/" & .Offset(, 1) & "/" & .Offset(, 2)
    End With
End Sub
 
Upvote 0
I cannot really help with the Shell script, but I think a "Worksheet_SelectionChange" event procedure, which is triggered any time a cell is selected, would be better than the "Worksheet_BeforeDoubleClick" event for what you want to do.
 
Upvote 0
I cannot really help with the Shell script, but I think a "Worksheet_SelectionChange" event procedure, which is triggered any time a cell is selected, would be better than the "Worksheet_BeforeDoubleClick" event for what you want to do.
I attempted to change it and rerun. Now it's giving me the following popup: Compile error: Procedure declaration does not match description of event or procedure having the same name.

Nothing has the same name so that's not correct. Not sure what the issue would be.
 
Upvote 0
Maybe this (placed in the worksheet code section):
VBA Code:
Sub Worksheet_SelectionChange(ByVal Target As Range)
    CreateObject("WScript.Shell").PopUp Target(1).Value, 2, "Title", 4096
End Sub
If you want to have no OK button, you would need to use a MsgBox-like userform.
 
Upvote 0
Maybe this (placed in the worksheet code section):
VBA Code:
Sub Worksheet_SelectionChange(ByVal Target As Range)
    CreateObject("WScript.Shell").PopUp Target(1).Value, 2, "Title", 4096
End Sub
If you want to have no OK button, you would need to use a MsgBox-like userform.
OK that seemed to do it. One final inquiry: instead of applying the Worksheet_SelectionChange to the entire worksheet, how would you restrict it to only activate within a certain range?
 
Upvote 0
Restricted to range A1:C3
VBA Code:
Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, [A1:C3]) Is Nothing Then _
    CreateObject("WScript.Shell").PopUp Target(1).Value, 2, "Title", 4096
End Sub
 
Upvote 0
Solution
Sub Worksheet_SelectionChange(ByVal Target As Range) If Not Intersect(Target, [A1:C3]) Is Nothing Then _ CreateObject("WScript.Shell").PopUp Target(1).Value, 2, "Title", 4096 End Sub
Bingo!! Many thanks to both of you for your help and suggestions!!
 
Upvote 0

Forum statistics

Threads
1,224,621
Messages
6,179,946
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top