Find all rows that have a value of a changed row

treeleaf20

Board Regular
Joined
Mar 17, 2009
Messages
154
I have a dependency column (column I) in my spreadsheet and a WBS ID (column A). If I change a date field (column J), I'd like the VBA to find all of the rows that have the changed WBS ID in it. How can I do this with VBA? Some of the dependency columns also have a comma separated list.

For example, say I have the following table:
WBS ID (column A)Dependency (column I)Start Date (column J)
1212/16/2019
23,112/01/2019
3112/19/2019

In this scenario, say I update the row with the WBS ID of 1. In this case, I'd like the system to find this in the Dependency column and have a foreach loop so I can update a value. So in this example, it would find the row for WBS ID 2 and 3.

Thank you in advance.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Put the following code in the events of your sheet

VBA Code:
Option Explicit
Public dic As Object

Private Sub Worksheet_Change(ByVal Target As Range)
  If Not Intersect(Target, Range("J:J")) Is Nothing Then
    If Target.Count > 1 Then Exit Sub
    If Target.Row = 1 Then Exit Sub
    Dim ini As Variant
    Set dic = CreateObject("Scripting.Dictionary")
    ini = Cells(Target.Row, "A").Value
    dic(ini) = Empty
    Call Fill_Dic(Cells(Target.Row, "I").Value)
    dic.Remove ini
    MsgBox Join(dic.keys, ",")
  End If
End Sub

Sub Fill_Dic(depen)
  Dim c As Variant, f As Range
  For Each c In Split(depen, ",")
    Set f = Range("A:A").Find(Trim(c), , xlValues, xlWhole)
    If Not f Is Nothing Then
      If Not dic.exists(f.Value) Then
        dic(f.Value) = Empty
        Call Fill_Dic(Cells(f.Row, "I").Value)
      End If
    End If
  Next
End Sub

SHEET EVENT
Right click the tab of the sheet you want this to work, select view code and paste the code into the window that opens up.

Go back to your sheet, modify a cell in column J, the code is automatically executed.
The result will be displayed in a message.
Note: You didn't say where you want the result, so I put it in a message.
 
Upvote 0

Forum statistics

Threads
1,214,560
Messages
6,120,217
Members
448,951
Latest member
jennlynn

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