Run userform when cell in range changes to a specific value

christchaaya

Board Regular
Joined
Apr 5, 2013
Messages
86
Hello gurus :)

I have a range of data validation list cells (c2:c300) and I'd like to call a userform when the user selects "Add..." from the dorpdown list of one of those cells.

I need this part of code because I'm trying to let the user add items to the validation list. If you have any alternative solution you're welcome to share it :D

Regards.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try like this: right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C2:C300")) Is Nothing And Target.Value Like "Add*" Then
    UserForm1.Show
End If
End Sub
 
Upvote 0
Try like this: right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C2:C300")) Is Nothing And Target.Value Like "Add*" Then
    UserForm1.Show
End If
End Sub


Works perfectly! Thank you :D
 
Upvote 0
To alter the selected Validation list try these 2 codes "Change Event" To show userform and pass Validation cell addresss, and Userform code with Textbox for Validation addition, and with Command Button to update selected validation list.
Change Event code:-
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 3 And Target.Count = 1 Then
        If Target.Value = "Add" Then
            Call UserForm2.Mytar(Target)
            UserForm2.Show
        End If
    End If
End Sub
Userform code:-
Based on "Userform2", with a TextBox:- "Textbox1" and a "CommandButton":- CommandButton1"
NB:- Copy this code to the top of your Userform Module
Code:
Option Explicit
Dim Ob1 As Object
Sub Mytar(ByRef nOb As Object)
    Set Ob1 = nOb
End Sub
Private Sub CommandButton1_Click()
Dim Temp As String
If Not TextBox1.text = vbNullString Then
    With Ob1.Validation
        Temp = .Formula1
        .Delete
        .Add Type:=xlValidateList, Formula1:=Temp & "," & TextBox1.text  
    End With
MsgBox " New Data Added"
Unload UserForm2
End If
End Sub
 
Last edited:
Upvote 0
To alter the selected Validation list try these 2 codes "Change Event" To show userform and pass Validation cell addresss, and Userform code with Textbox for Validation addition, and with Command Button to update selected validation list.
Change Event code:-
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 3 And Target.Count = 1 Then
        If Target.Value = "Add" Then
            Call UserForm2.Mytar(Target)
            UserForm2.Show
        End If
    End If
End Sub
Userform code:-
Based on "Userform2", with a TextBox:- "Textbox1" and a "CommandButton":- CommandButton1"
NB:- Copy this code to the top of your Userform Module
Code:
Option Explicit
Dim Ob1 As Object
Sub Mytar(ByRef nOb As Object)
    Set Ob1 = nOb
End Sub
Private Sub CommandButton1_Click()
Dim Temp As String
If Not TextBox1.text = vbNullString Then
    With Ob1.Validation
        Temp = .Formula1
        .Delete
        .Add Type:=xlValidateList, Formula1:=Temp & "," & TextBox1.text  
    End With
MsgBox " New Data Added"
Unload UserForm2
End If
End Sub


Your code seems good to me but my problem is that im working with dependent lists. I got list1 which contains "IN" and "OUT" then i got list "IN" with some items and "OUT" with different items. When the user selects IN in any cell in column b he can chose between INlist items in column c otherwise if he selects OUT in column b he will be able to chose betweekn OUTlist items in column c. What I'm doing is let the user add items to INlist and OUTlist.

Column c validation formula is "INDIRECT($B$2)"
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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