Need VBA to run each time selection is made in data validation list

General Ledger

Active Member
Joined
Dec 31, 2007
Messages
460
Dear All,

Using Excel 2003: I have a macro that I want to run every time a selection is made from a drop down list.

Cell B4 has data validation list. I want the below code to run every time the user makes a selection from the drop down list in B4. Currently, it only runs when the active cell is not B4 and then B4 is selected (when the selection changes).

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not (Application.Intersect(Target, Range("B4")) Is Nothing) Then
If Len(Trim(Range("B4"))) < 5 Then
ActiveSheet.Range("B6") = "No template"
Else: ActiveSheet.Range("B6") = "Template"
End If
End If
End Sub

Best regards,

GL
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "B4" Then
    If Len(Trim(Range("B4").Value)) < 5 Then
        Me.Range("B6").Value = "No template"
    Else
        Me.Range("B6").Value = "Template"
    End If
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,737
Messages
6,126,563
Members
449,318
Latest member
Son Raphon

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