Run macro when cell is altered

JimmieNeu

New Member
Joined
Oct 22, 2018
Messages
28
Office Version
  1. 365
Platform
  1. Windows
Is there a way to do this?

The Working Macro:

Sub test()
If [C3] = "!!!!" Then
[C2] = [C2]
ElseIf [C3] = "PVC" Then
[C2] = [C2]
ElseIf [C3] = "Plywood" Then
[C2] = [C2]
ElseIf [C3] = "Starboard" Then
[C2] = [C2]
ElseIf [C3] = "MDF" Then
[C2] = [C2]
ElseIf [C3] = "Custom" Then
[C2] = "Custom"
End If
End Sub

What I have tried:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$3" Then
Sub test()
If [C3] = "!!!!" Then
[C2] = [C2]
ElseIf [C3] = "PVC" Then
[C2] = [C2]
ElseIf [C3] = "Plywood" Then
[C2] = [C2]
ElseIf [C3] = "Starboard" Then
[C2] = [C2]
ElseIf [C3] = "MDF" Then
[C2] = [C2]
ElseIf [C3] = "Custom" Then
[C2] = "Custom"
End If
End Sub
End If
End Sub

Based on this thread:
 

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.
You cannot imbed a procedure inside of another procedure.
Either put the code right in it, or call one procedure from another, i.e. assuming that your original procedure works, either this:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$3" Then
If [C3] = "!!!!" Then
[C2] = [C2]
ElseIf [C3] = "PVC" Then
[C2] = [C2]
ElseIf [C3] = "Plywood" Then
[C2] = [C2]
ElseIf [C3] = "Starboard" Then
[C2] = [C2]
ElseIf [C3] = "MDF" Then
[C2] = [C2]
ElseIf [C3] = "Custom" Then
[C2] = "Custom"
End If
End If
End Sub
or this:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$3" Then
    Call test
End If
End Sub

Though I am not really sure what the point of this is:
VBA Code:
[C2] = [C2]
Why are you setting a value to itself?
I don't think that serves any purpose.
 
Upvote 0

Forum statistics

Threads
1,215,106
Messages
6,123,122
Members
449,096
Latest member
provoking

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