JCarney0899
New Member
- Joined
- Jul 22, 2024
- Messages
- 3
- Office Version
- 365
- Platform
- Windows
This code currently deletes the entire row based on criteria set in cell K from Sheet 1(Roster) to Sheet 2(Lead) but I need this code to copy rows A through G in Sheet 1(Roster) to Sheet 2(Lead) if cell K shows the criteria of "Interested". I am new to VBA & found this code (& it worked just not exactly what I need it to work for) in a forum.
Sub MoveBasedOnValue()
Dim xRg As Range
Dim xCell As Range
Dim A As Long
Dim B As Long
Dim C As Long
Dim D As Long
Dim E As Long
Dim F As Long
Dim G As Long
A = Worksheets("Roster").UsedRange.Rows.Count
B = Worksheets("Lead").UsedRange.Rows.Count
If B = 1 Then
If Application.WorksheetFunction.CountA(Worksheets("Lead").UsedRange) = 0 Then B = 0
End If
Set xRg = Worksheets("Roster").Range("K3:K" & A)
On Error Resume Next
Application.ScreenUpdating = False
For C = 1 To xRg.Count
If CStr(xRg(C).Value) = "Interested" Then
xRg(C).EntireRow.Copy Destination:=Worksheets("Lead").Range("A" & B + 1)
xRg(C).EntireRow.Delete
If CStr(xRg(C).Value) = "Interested" Then
C = C - 1
End If
B = B + 1
End If
Next
Application.ScreenUpdating = True
End Sub
This is the worksheet code
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim xRg As Range
Dim xCell As Range
Dim A As Long
Dim B As Long
Dim C As Long
Dim D As Long
Dim E As Long
Dim F As Long
Dim G As Long
A = Worksheets("Roster").UsedRange.Rows.Count
B = Worksheets("Lead").UsedRange.Rows.Count
If B = 1 Then
If Application.WorksheetFunction.CountA(Worksheets("Lead").UsedRange) = 0 Then B = 0
End If
Set xRg = Worksheets("Roster").Range("K3:K" & A)
On Error Resume Next
Application.ScreenUpdating = False
For C = 1 To xRg.Count
If CStr(xRg(C).Value) = "Interested" Then
xRg(C).EntireRow.Copy Destination:=Worksheets("Lead").Range("A" & B + 1)
xRg(C).EntireRow.Delete
C = C - 1
End If
Next
Application.ScreenUpdating = True
End Sub
Sub MoveBasedOnValue()
Dim xRg As Range
Dim xCell As Range
Dim A As Long
Dim B As Long
Dim C As Long
Dim D As Long
Dim E As Long
Dim F As Long
Dim G As Long
A = Worksheets("Roster").UsedRange.Rows.Count
B = Worksheets("Lead").UsedRange.Rows.Count
If B = 1 Then
If Application.WorksheetFunction.CountA(Worksheets("Lead").UsedRange) = 0 Then B = 0
End If
Set xRg = Worksheets("Roster").Range("K3:K" & A)
On Error Resume Next
Application.ScreenUpdating = False
For C = 1 To xRg.Count
If CStr(xRg(C).Value) = "Interested" Then
xRg(C).EntireRow.Copy Destination:=Worksheets("Lead").Range("A" & B + 1)
xRg(C).EntireRow.Delete
If CStr(xRg(C).Value) = "Interested" Then
C = C - 1
End If
B = B + 1
End If
Next
Application.ScreenUpdating = True
End Sub
This is the worksheet code
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim xRg As Range
Dim xCell As Range
Dim A As Long
Dim B As Long
Dim C As Long
Dim D As Long
Dim E As Long
Dim F As Long
Dim G As Long
A = Worksheets("Roster").UsedRange.Rows.Count
B = Worksheets("Lead").UsedRange.Rows.Count
If B = 1 Then
If Application.WorksheetFunction.CountA(Worksheets("Lead").UsedRange) = 0 Then B = 0
End If
Set xRg = Worksheets("Roster").Range("K3:K" & A)
On Error Resume Next
Application.ScreenUpdating = False
For C = 1 To xRg.Count
If CStr(xRg(C).Value) = "Interested" Then
xRg(C).EntireRow.Copy Destination:=Worksheets("Lead").Range("A" & B + 1)
xRg(C).EntireRow.Delete
C = C - 1
End If
Next
Application.ScreenUpdating = True
End Sub