VBA Update a sub set of records

Al Del

Board Regular
Joined
Jan 9, 2007
Messages
112
I am using the following macro to place a "w" in column M (9) of the target record of a worksheet when colmun D gets the entry "Filled".

Code:
    Dim lastrow As Integer
    lastrow = Range("D" & Rows.Count).End(xlUp).row
    
    'If Status is "Filled" place a "w" in Results
    'Range("D2:D" & lastrow) Is the Target it defines the column D as the target area
    If Not Intersect(Target, Range("D2:D" & lastrow)) Is Nothing Then
        If Target <> "Filled" Then
            Target.Offset(, 9) = vbNullString
            Else: Target.Offset(, 9) = "w"
        End If
     End If

I would like to enter a "w" into col M of all records, that have the same entry in column K of the target row of the list, when anyone of these records gets the entry "Filled" put in col D of one of these records.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
When "Filled" is entered in the target record in col D, I want "w" to be entered in all records, col M, that have the same entry in col K.
 
Upvote 0
When "Filled" is entered in the target record in col D, I want "w" to be entered in all records, col M, that have the same entry in col K.

It is still unclear as to what you want column K value to be the same as. Can you show a before and after example of what you expect?
Col D|Col K|Col M
Filled|---?--|--w--
 
Upvote 0
Column K would not change, it is used to define the subset of records to be updated with the "w" in col M.
Ideally I would like to enter the oldest date in the subset in the target record date cell, col H.
The numbers are just for reference.

HTML:
Before column D change  
  Col D        Col H         Col K    Col M
  Status      Date          Job        Result
1 Sent        3/10/2018    a        
2 Sent        5/11/2018    b        
3 Interview  4/12/2018    a        
4 Rejected   5/15/2018    c        
5 Interview  6/14/2018    b        
6 Sent        7/07/2018    a        

After Enter Filled in col D, record 3.
3 Filled        3/10/2018    a       w
1 Sent        3/10/2018    a        w
6 Sent        7/07/2018    a        w
2 Sent        5/11/2018    b        
4 Rejected   5/15/2018    c        
5 Interview  6/14/2018    b
 
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count <> 1 Then Exit Sub
Application.EnableEvents = False
    If Not Intersect(Target, Range("D:D")) Is Nothing Then
        If LCase(Target.Value) = "filled" Then
            Range("K:K").AutoFilter 1, Target.Offset(, 7).Value
            Range("K2", Cells(Rows.Count, "K").End(xlUp)).Offset(, 2).SpecialCells(xlCellTypeVisible).Value = "w"
            AutoFilterMode = False
        End If
    End If
Application.EnableEvents = True
End Sub

In the futue, you should notify us if you are cross posting so we can check to see if a solution has been provided in another forum and not spend a lot of time duplicating effort.
 
Last edited:
Upvote 0
Yes I will, thank you.

I ran the procedure and got an AutoFillter out of range error, turns out the header of my table starts at row 2, so I think I made the correct changes. If I input "Filled" col D no update of column M occurs. I'm using a table not a range in case that makes a difference.
 
Upvote 0
Yes I will, thank you.

I ran the procedure and got an AutoFillter out of range error, turns out the header of my table starts at row 2, so I think I made the correct changes. If I input "Filled" col D no update of column M occurs. I'm using a table not a range in case that makes a difference.
I am going to drop off of this thread. When you can get all of your parameters defined so that they are clear to the reader and can properly describe your worksheet layout and conditions, maybe someone else will pick up on the thread and provide assistance.
Regards, JLG
 
Upvote 0
Ok, I think the only difference was the starting row. I actually moved the table header to the first row and still no update result?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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