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
 

Some videos you may like

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,831
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
75,831
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,428
Messages
5,528,698
Members
409,830
Latest member
KT50

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top