VBA condition rules based on drop down list

alphabetagamma

New Member
Joined
Jun 9, 2017
Messages
1
Hi Guy's

I am very new to VBA and i am struggling with a code based on the option which are selected from the drop-down list.

Drop down list is in column D in the sheet "MyData". Columns A-C will be populated with data. What I want to do is: if option "Terminate" or "End" are chosen from the drop-down list in column D, macro will switch/open sheet "Terms" and automatically copy data from that row in "MyData" columns A-C which are in the same order in "Terms".


Is there a simple way to do this?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I'm assuming you want the range in Sheets("MyData") copied into the same exact row in Sheet("Terms")
That's the way I understand your posting.

Put this script in sheet named "MyData"

This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab Named "MyData"
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D:D")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Dim ans As String
Dim r As Long
r = Target.Row
ans = Target.Value
If ans = "Terminate" Or ans = "End" Then Range(Cells(r, 1), Cells(r, 3)).Copy Sheets("Terms").Range("A" & r)
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,874
Members
452,363
Latest member
merico17

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