fishymuffin
New Member
- Joined
- Jan 18, 2022
- Messages
- 1
- Office Version
- 365
- Platform
- Windows
I have a file with three worksheets.
Sheet1 is a summary of all clients.
Sheet2 has a table that copies only clients with "active" status from Sheet1, Sheet3 has a table that copies only clients with "buyer" status from Sheet1.
Is it possible to write a vba code that will delete rows from Sheet2's table if their status in Sheet1 changed from "active" to any other status?
Here is the code that copies the data from Sheet1 to Sheet2 (it's the same for Sheet3, just with different table and sheet names):
Alternatively, a code to "refresh" the status column in Sheet2 to show the new status from Sheet1 is also okay, however less ideal.
Thanks!
Sheet1 is a summary of all clients.
Sheet2 has a table that copies only clients with "active" status from Sheet1, Sheet3 has a table that copies only clients with "buyer" status from Sheet1.
Is it possible to write a vba code that will delete rows from Sheet2's table if their status in Sheet1 changed from "active" to any other status?
Here is the code that copies the data from Sheet1 to Sheet2 (it's the same for Sheet3, just with different table and sheet names):
VBA Code:
Sub CopyActiveRecords()
Dim StatusCol As Range
Dim Status As Range
Dim PasteCell As Range
Set StatusCol = Sheet1.Range("A2:I150")
For Each Status In StatusCol
If Sheet2.Range("A2") = "" Then
Set PasteCell = Sheet2.Range("A2")
Else
Set PasteCell = Sheet2.Range("A1").End(xlDown).Offset(1, 0)
End If
If Status = "active" Then Status.EntireRow.Copy PasteCell
Next Status
With ActiveSheet
Set Rng = Range("A1", Range("B1").End(xlDown))
Rng.RemoveDuplicates Columns:=Array(1, 2), Header:=xlYes
End With
End Sub
Alternatively, a code to "refresh" the status column in Sheet2 to show the new status from Sheet1 is also okay, however less ideal.
Thanks!