I want to find people with a specific value in one of the columns in my sheet, cut their row, and paste them in a specified tab. (Even better would be if I can search for specific words in the cells of one of the columns since there are fiscal years involved that I don't want to fix annually.)
I'm looking for anyone who has "FD.Matching Gifts FY22" in column D. Or just the words Matching Gift. I want to cut those rows and paste them in my Matching tab, then delete the empty row.
I tried this, which I know wouldn't get me everything I want but it would have been a start:
Sub CopyMatching()
Dim StatusCol As Range
Dim Status As Range
Dim PasteCell As Range
Set StatusCol = Sheet1.Range("D2:D1000")
For Each Status In StatusCol
If Sheet2.Range("A2") = "" Then
Set PasteCell = Sheet2.Range("A2")
Else
Set PasteCell = Sheet2.Range("A1").End(x1Down).Offset(1, 0)
End If
If Status = "FD.Matching Gifts FY22" Then Status.Offset(0, -3).Resize(1, 24).Copy PasteCell
Next Status
End Sub
The error here being
"Application-defined or object defined error"
Then I found this but I don't think I put the pieces in the right places:
Sub MoveMatchRows()
MoveRows "FD.MatchingGifts FY22"
End Sub
Sub MoveRows(Unit As String)
With Sheets("Sheet1").Range("A1").CurrentRegion
.AutoFilter ' switch filtering on or clear previous filter
.AutoFilter 4, appeal_desc ' filter so that only rows with "NTS" or whichever unit is passed in, are visible
If .Columns(4).SpecialCells(xlVisible).Count = 4 Then
' none found
MsgBox "No " & appeal_desc & " rows found"
Else
' With .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlVisible)
' now dealing with the data only, not the headings
.Copy
' paste the data to the row after the last used row in new sheet for the unit
Sheets(appeal_desc & " New").Cells(Rows.Count, 1).End(xlUp).Offset(1).PasteSpecial xlAll
.EntireRow.Delete ' remove the copied rows
End
End If
.AutoFilter ' remove the filter
End With
End Sub
This error was
"script out of range"
