How do I update the screen -without clicking out to refresh?

Cmack

New Member
Joined
May 23, 2023
Messages
9
Office Version
  1. 365
Platform
  1. Windows
I have a code to deactivate a command button on sheet 2 when cell A1 is being used.
I have to click on sheet 2 then back to sheet 1 then back to sheet 2 to disable/enable command button (to activate it)
Is there a way to update the commandbutton instantly? (execute the program)

VBA Code:
Private Sub Worksheet_Activate()
Dim CV As Boolean
If Worksheets("Sheet1").Range("A1").Value = "" Then CV = False
If CV = False Then Worksheets("Sheet2").CommandButton1.Enabled = False
If Worksheets("Sheet1").Range("A1").Value > 0 Then CV = True
If CV = True Then Worksheets("Sheet2").CommandButton1.Enabled = True
End sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I have tried
Application.ScreenUpdating = True
ActiveSheet.Calculate
Application.EnableEvents = True
Application.WindowState = Application.WindowState
With limited success- Perhaps these code fragments are in the wrong place :(
Any help appreciated :)
 
Upvote 0
I worked it out, for those that need it - use the sheet change command

Private Sub Worksheet_Change(ByVal Target As Range)
Dim CV As Boolean

If Worksheets("Sheet1").Range("A1").Value = "" Then CV = False
If CV = False Then Worksheets("Sheet2").CommandButton1.Enabled = False
If Worksheets("Sheet1").Range("A1").Value > 0 Then CV = True
If CV = True Then Worksheets("Sheet2").CommandButton1.Enabled = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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