rtaylor1987
New Member
- Joined
- Nov 30, 2021
- Messages
- 6
I'm working on a project where I need to be able to read data from different cells and sort these into different sheets depending on value.
Essentially, when you load data - it should be able to read the following:
Cases that are listed as active (If value = "active" then move to sheet Active)
cases that are pending (If Start Date is less than 30 days, it's flagged with a "y" in the system, so if Value="y" then move to "Pending"
cases that are already closed (If "closed date" is NOT null) then move them to the "closed" sheet
I have the Active part working, so I thought the code was fairly straight forward but it doesn't appear to like me pushing IF statements back-to-back. (I'm still fairly new to VB so it's most likely user error)
Any way to get each of these separate functions executed when worksheet change is detected?
Essentially, when you load data - it should be able to read the following:
Cases that are listed as active (If value = "active" then move to sheet Active)
cases that are pending (If Start Date is less than 30 days, it's flagged with a "y" in the system, so if Value="y" then move to "Pending"
cases that are already closed (If "closed date" is NOT null) then move them to the "closed" sheet
I have the Active part working, so I thought the code was fairly straight forward but it doesn't appear to like me pushing IF statements back-to-back. (I'm still fairly new to VB so it's most likely user error)
Any way to get each of these separate functions executed when worksheet change is detected?
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 28 And Target.Cells.Count = 1 Then
If LCase(Target.Value) = "active" Then
With Target.EntireRow
.Copy Sheets("Active").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
.Delete
End With
End If
End If
If Target.Column = 18 And Target.Cells.Count = 1 Then
If LCase(Target.Value) = "y" Then
With Target.EntireRow
.Copy Sheets("Pending").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
.Delete
End With
End If
End If
If Target.Column = 12 And Target.Cells.Count = 1 Then
If Not LCase(Target.Value) = "null" Then
With Target.EntireRow
.Copy Sheets("Closed").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
.Delete
End With
End If
End If
End Sub