Posting in the hope I’m not flame grilled. Bluntly, I’m a novice and though I’m trying my best, Rome wasn’t built in a day and I’m stuck.
I’ve had some help elsewhere and Kudos to the person, they are in a hugely different timezone and I don’t want to bombard them.
I pull a report from Power BI into Excel. Current coding I have now is to delete bottom 3 rows, remove rows with duplicate PO numbers in Column A (1), Filter and remove every entry except “Approved” in Column J (10). This has been tested and works great.
There are still thousands of lines left which need filtering and deleting to leave the data I want, and here is the sticking point…
Column H (8) is where names are input in the original program. When an action has been taken we prefix this with an “R”. Unfortunately each colleague seems to have their own way of doing this and there are multiple entries to try and go through. Combine multiple R prefix methods with many names and filtering / deleting these prefixed entries becomes everyone’s worst nightmare. There are some other prefixes too but the Rs are the absolute bane of our lives. 1000s of lines. We want to remove all prefixed entries from the worksheet.
The most common theme is an “R” followed by a space or a hyphen. The below is a capture of the ones I’ve spotted so far, with Test Text input rather than names here for obvious reasons (Real Data is to reflect where a name we want to retain might start with an R, i.e. Rebecca and the XX or * prefix is another one we filter and delete results for):
R – Test Text
R Test Text
R-Test Text
RTest Text
Real Data
R-
R Test Text
R- Test Text
R_Test Text
XX Test Text
*Test Text
The ones with RTest Text probably will have to be done manually but can all other instances have those rows removed via VBA or are there just too many?
I tried to attempt coding based on some info I was given but it went horribly wrong and deleted everything I wanted and left a few entries that I didn’t want. Please see below:
`Option Explicit
Sub RsRemovalTest()
Dim ws As Worksheet, LRow As Long
Set ws = ActiveSheet
LRow = ws.Cells.Find(“*”, , xlFormulas, , 1, 2).Row
ws.Cells(LRow, 1).Offset(-2).Resize(3).EntireRow.Delete
If ws.AutoFilterMode Then ws.AutoFilter.ShowAllData
With ws.Range("A1").CurrentRegion
.RemoveDuplicates Columns:=1, Header:=xlYes
.AutoFilter 10, "<>Approved"
If .SpecialCells(xlCellTypeVisible).Address <> .Rows(1).Address Then
.Offset(1).EntireRow.Delete
End If
.AutoFilter 8, "R *", 2, "R-*", 3, "XX*"
If .SpecialCells(xlCellTypeVisible).Address <> .Rows(1).Address Then
.Offset(1).EntireRow.Delete
End If
.AutoFilter
End With
End Sub`
I’d be ever so grateful for help, but if novices aren’t permitted to ask, I understand and thanks to anyone taking the time to read.
Tried to search for info online but I lack the understanding on where I put things and how to rectify the wrong info being deleted.
SalsaMoon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.