Subroutine for change to a value on a worksheet

craigyg

Board Regular
Joined
Dec 14, 2005
Messages
114
Hope this question isn't too vague but here goes:

I am able to write subs based on click and change events for a button. I would like to be able to write the same kind of subs for change to a value or range of values on a worksheet. How can i do this?

Thanks-

Craig
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,303
Office Version
  1. 365
Platform
  1. Windows
Craig

You would use worksheet or workbook events.

To access a worksheet's module, where the code will go, right click it's tab and select View Code.

You should now have 2 dropdowns above a code window.

If you select Worksheet from the left one you should see this.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub
This is the default event for a worksheet and is triggered when selection on the worksheet changes.

The parameter Target is the range that was changed.

There are various other worksheet events that you'll see listed in the right dropdown.
 

craigyg

Board Regular
Joined
Dec 14, 2005
Messages
114
Userform

Related question: What about if I want to do the same thing as before but I want this subroutine to be inside a userform module? (I would like this change to the worksheet to initiate changes on the userform).
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,303
Office Version
  1. 365
Platform
  1. Windows
craig

Can you give more information?

There are various ways you can have worksheets/userforms interact with each other.
 

Forum statistics

Threads
1,141,144
Messages
5,704,541
Members
421,353
Latest member
jekoxien15

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
Top