iis there a way to cause the Get.Cell function to dynamically update

bearcub

Well-known Member
Joined
May 18, 2005
Messages
734
Office Version
  1. 365
  2. 2013
  3. 2010
  4. 2007
Platform
  1. Windows
I am using the Get.Cell Excel 4 macro function to show the actually number format being displayed in a cell (Get.Cell(7,A1)).

I would like the Get.cell Cell to update automatically when I change the cell format. The only way it updates now is if I enter the data in the source or I click and do something in the cell that houses the Get.Cell formula.

I was using the Calculate function in the SelectionChange worksheet event but that doesn't seem to help.

Do you know of what that would cause functions like this to update dynamically without my having to manually perform some action on the impacted cells (both the source and formula cells)?

I was thinking if I could cause some event to happen on the spreadsheet somehow (like using the Calculate VBA function) that it create some sort of movement (like moving a spiderweb) that trigger the function to update automatically.

Has anyone found a solution for this issue over the years?

Thank you for your help,

Michael
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
As you've found, changing format doesn't trigger calculation. There's no way short of some exotic windows API.
 
Upvote 0
If you are dealing with just one cell- example ( A1 ) then you could use this trick :

Code goes in the ThisWorkbook Module :
Code:
Option Explicit

Private WithEvents oCmndBars As CommandBars
Private vPrevNumberFormat As Variant
    
Private Const TARGET_CELL_Addr As String = "Sheet1!$A$1"  [B][COLOR=#008000]' <== Change this cell addr CONST as required.[/COLOR][/B]


Private Sub Workbook_Open()
    Call HookCommandBars
End Sub


Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
   If oCmndBars Is Nothing Then Call HookCommandBars
End Sub


Private Sub HookCommandBars()
    Set oCmndBars = Application.CommandBars
    vPrevNumberFormat = Range(TARGET_CELL_Addr).NumberFormat
    Call oCmndBars_OnUpdate
End Sub


Private Sub oCmndBars_OnUpdate()
    With Application.CommandBars
        .FindControl(ID:=2040).Enabled = Not .FindControl(ID:=2040).Enabled
    End With
    If vPrevNumberFormat <> Range(TARGET_CELL_Addr).NumberFormat Then
        Range(TARGET_CELL_Addr).Parent.Calculate
    End If
    vPrevNumberFormat = Range(TARGET_CELL_Addr).NumberFormat
End Sub

Note:
To make this work for more than one cell, the code will need some tweaking.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,161
Members
453,021
Latest member
Justyna P

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