ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Cell Value on Toolbar (https://www.excelbanter.com/excel-discussion-misc-queries/61168-cell-value-toolbar.html)

HilcrRWise

Cell Value on Toolbar
 

Is it possible to show the value of a cell on a custom toolbar. Cell
location will not change, but cell content will.


--
HilcrRWise
------------------------------------------------------------------------
HilcrRWise's Profile: http://www.excelforum.com/member.php...o&userid=11699
View this thread: http://www.excelforum.com/showthread...hreadid=494807


Bob Phillips

Cell Value on Toolbar
 
One way

Option Explicit

Const WS_RANGE As String = "B10"

Private Sub Worksheet_Activate()
Dim oCtl As CommandBarControl

On Error Resume Next
Set oCtl = Application.CommandBars.FindControl(Tag:="cellValu e")
oCtl.Delete
On Error GoTo 0
With Application.CommandBars("Standard"). _
Controls.Add(Type:=msoControlButton)
.Tag = "cellValue"
.Style = msoButtonCaption
.Caption = Me.Range(WS_RANGE).Value
End With
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
Dim oCtl As CommandBarControl

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
Set oCtl = CommandBars.FindControl(Tag:="cellValue")
oCtl.Caption = Target.Value
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.




--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"HilcrRWise" wrote
in message ...

Is it possible to show the value of a cell on a custom toolbar. Cell
location will not change, but cell content will.


--
HilcrRWise
------------------------------------------------------------------------
HilcrRWise's Profile:

http://www.excelforum.com/member.php...o&userid=11699
View this thread: http://www.excelforum.com/showthread...hreadid=494807





All times are GMT +1. The time now is 02:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com