How to run macro when textbox changes?

JollyRoger01

New Member
Joined
Jun 1, 2021
Messages
12
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
This has been asked many times before, but all of the answers I can find focus on user form textboxes whereas mine is a simple Insert > Textbox which points to another cell using the = in the formula bar. This cell is on another page and it extracts a values from a pivot table cell (="Showing data from "&IF(TODAY()-D252<1,"today",IF(TODAY()-D252<2,"yesterday",TODAY()-D252&" days ago"))).

All I want to do is run a macro when the text in this textbox changes. The textbox name is "Date Selected". Can someone please tell me what I need to write and where?
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
if you insert Textbox form ActiveX controls at Developer Tab. Then You Should go to Properties of Textbox and at the LinkedCell Option add One Cell Address.
After Do that, when Change Textbox Data, Also Linked Cell Data Changes. Then You can use Worksheet Change Event based LinkedCell.

For Example if your LinkedCell is Cell E2, Then Right Click On Sheet name at Excel window and Select View Code. Then Paste This Code:
Change Green part of code to your code.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("E2")) Is Nothing Then Exit Sub
'' INsert Your Code Here
End Sub
 
Upvote 0
if you insert Textbox form ActiveX controls at Developer Tab. Then You Should go to Properties of Textbox and at the LinkedCell Option add One Cell Address.
After Do that, when Change Textbox Data, Also Linked Cell Data Changes. Then You can use Worksheet Change Event based LinkedCell.

For Example if your LinkedCell is Cell E2, Then Right Click On Sheet name at Excel window and Select View Code. Then Paste This Code:
Change Green part of code to your code.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("E2")) Is Nothing Then Exit Sub
'' INsert Your Code Here
End Sub
I have many of these textboxes and am not able to redo them all unfortunately. I just want to detect changes in non-form/non-ActiveX textboxes.
 
Upvote 0
you don't need to redo them. at Developer tab, Enable Design mode, Right click on Textbox, Select Properties, then go to LinkedCell
 
Upvote 0
I c
you don't need to redo them. at Developer tab, Enable Design mode, Right click on Textbox, Select Properties, then go to LinkedCell
I am not seeing the Properties option that will give me LinkedCell

1629964166451.png
 
Upvote 0
When Select Textbox, Then at the developer tab, you can select properties at the right side of Design mode
You don't Use Activex Control, Then You cannot See LinkedCell. You Should Use ActiveX TextBoxes
What about Assign Macro at Right Click Menu for Adding Macro
 
Last edited:
Upvote 0
When Select Textbox, Then at the developer tab, you can select properties at the right side of Design mode
You don't Use Activex Control, Then You cannot See LinkedCell. You Should Use ActiveX TextBoxes
What about Assign Macro at Right Click Menu for Adding Macro
I can add a macro on selection of the textbox if I want, but that is not the aim. The aim is to run a macro when the CURRENT textbox (as it is, no ActiveX etc.) text changes.

I have enabled Design View, selected the textbox then selected Properties from the Developer tab. I am only shown properties for the sheet.

1629966345802.png
 
Upvote 0
I think Your only Way is ActiveXControls.
 
Upvote 0
I worked it out. I used the following on the sheet with the pivot table to change the text box.

Private Sub Worksheet_PivotTableChangeSync(ByVal Target As PivotTable)
Worksheets("PMR New Today").Activate
Call UPDATE_CHART_TEXTBOXES
Call UPDATE_TEXTBOX_MAIN
Call UPDATE_TEXTBOX_REFRESH
Call UPDATE_TEXTBOX_DATE_SELECTED
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,794
Members
449,048
Latest member
greyangel23

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