Run Macro from Drop Down List plus Update when Source Changes

janeee

New Member
Joined
Jul 6, 2015
Messages
1
I am learning VBA and trying to piece together what I know to automate a spreadsheet.

I have a macro that pulls from two source sheets to develop a matrix on a Master spreadsheet. The macro runs based on selections from a drop down list. The macro is an index/match function that pulls the fields from the source sheets.

I need to update the Master spreadsheet when a change is made to either of the source sheets. The macro is below and is on the Master spreadsheet.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim n As Long
'here 5 is column number 5 which is column E
If (Target.Column <> 5) Then GoTo Exit Sub

Application.EnableEvents = False

thisrow = Target.Row
RiskInput = Cells(thisrow, 5)

If RiskInput = "" Then
'now you can comment out the code if it does not make sense
'but the idea is if the cell in column C has been cleared out,
'corresponding date and time should be cleared out too
Cells(thisrow, "D") = ""
Cells(thisrow, "F") = ""
Cells(thisrow, "G") = ""

Else
Cells(thisrow, 4) = Application.WorksheetFunction.Index(Sheets("Risks").Range("A2:A999"), Application.WorksheetFunction.Match(RiskInput, Sheets("Risks").Range("B2:B999"), 0), 0)
Cells(thisrow, 6) = Application.WorksheetFunction.Index(Sheets("Risks").Range("c2:c999"), Application.WorksheetFunction.Match(RiskInput, Sheets("Risks").Range("B2:B999"), 0), 0)
Cells(thisrow, 7) = Application.WorksheetFunction.Index(Sheets("Risks").Range("d2:d999"), Application.WorksheetFunction.Match(RiskInput, Sheets("Risks").Range("B2:B999"), 0), 0)
End If

Application.EnableEvents = True
End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,214,808
Messages
6,121,681
Members
449,048
Latest member
81jamesacct

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