Hi all,
I am a newbie and I would appreciate if someone could help to correct my code that is intended to delete all rows of a worksheet, excluding the rows starting by"2018" and the rows with some numbers separated by comas. the datasheet is setup as csv within column A and starting in A1. Then I am looking for a code that can move the numbers (in the example below) to the row above at the end of the preceding row starting by 2018. I hope it makes sense.
As an example of the dataset:
Configurable Alerts
Report ID:
Run Date:
Run Time:
TEXT_SYS801
16/12/2018
22:30:49 UTC
Page 1 of 34
Enterprise Performance Mgt
78) PSFR data blablabla by blabla (medium priority)
This alert gives bla bla bla bla to partners.
2018,...,...
2018, 1, 95716, 10021703, NA, TEXT (PHI), PHL, TEXT,Text Text Text,
10031793, 2448.83
2018,...,...
3000.95
2018,...,...
2018,...,...
Configurable Alerts
Report ID:
Run Date:
Run Time:
TEXT_SYS801
16/12/2018
22:30:49 UTC
Page 2 of 34
2018,...,...
2018,...,...
2018,...,...
The code
Sub kTest()
Dim r As Range
Dim c As Range
Dim i As Long
Dim x, Flg As Boolean, Skip As Boolean
Const SearchKeysBeginsWith As String = "Configurable,Run,HCR,Page,Enterprise" '<< add more words separated by comma
Const SearchKeysContains As String = "PSFR" '<< add more words separated by comma
Set r = Range("a1:a3000") '<< adjust to suit
Application.ScreenUpdating = 0
With r
x = Split(SearchKeysBeginsWith, ",")
1:
For i = 0 To UBound(x)
.AutoFilter 1, IIf(Flg, "*" & x(i) & "*", x(i) & "*")
On Error Resume Next
Set c = .Cells(1).Offset(1).Resize(.Rows.Count - 1, 1).SpecialCells(12)
On Error GoTo 0
If Not c Is Nothing Then
c.EntireRow.Delete
End If
Next
If Not Skip Then
x = Split(SearchKeysContains, ",")
Flg = True: Skip = True: GoTo 1
End If
.AutoFilter
End With
Application.ScreenUpdating = 1
End Sub
Thanks for the help much appreciated,
MRD
I am a newbie and I would appreciate if someone could help to correct my code that is intended to delete all rows of a worksheet, excluding the rows starting by"2018" and the rows with some numbers separated by comas. the datasheet is setup as csv within column A and starting in A1. Then I am looking for a code that can move the numbers (in the example below) to the row above at the end of the preceding row starting by 2018. I hope it makes sense.
As an example of the dataset:
Configurable Alerts
Report ID:
Run Date:
Run Time:
TEXT_SYS801
16/12/2018
22:30:49 UTC
Page 1 of 34
Enterprise Performance Mgt
78) PSFR data blablabla by blabla (medium priority)
This alert gives bla bla bla bla to partners.
2018,...,...
2018, 1, 95716, 10021703, NA, TEXT (PHI), PHL, TEXT,Text Text Text,
10031793, 2448.83
2018,...,...
3000.95
2018,...,...
2018,...,...
Configurable Alerts
Report ID:
Run Date:
Run Time:
TEXT_SYS801
16/12/2018
22:30:49 UTC
Page 2 of 34
2018,...,...
2018,...,...
2018,...,...
The code
Sub kTest()
Dim r As Range
Dim c As Range
Dim i As Long
Dim x, Flg As Boolean, Skip As Boolean
Const SearchKeysBeginsWith As String = "Configurable,Run,HCR,Page,Enterprise" '<< add more words separated by comma
Const SearchKeysContains As String = "PSFR" '<< add more words separated by comma
Set r = Range("a1:a3000") '<< adjust to suit
Application.ScreenUpdating = 0
With r
x = Split(SearchKeysBeginsWith, ",")
1:
For i = 0 To UBound(x)
.AutoFilter 1, IIf(Flg, "*" & x(i) & "*", x(i) & "*")
On Error Resume Next
Set c = .Cells(1).Offset(1).Resize(.Rows.Count - 1, 1).SpecialCells(12)
On Error GoTo 0
If Not c Is Nothing Then
c.EntireRow.Delete
End If
Next
If Not Skip Then
x = Split(SearchKeysContains, ",")
Flg = True: Skip = True: GoTo 1
End If
.AutoFilter
End With
Application.ScreenUpdating = 1
End Sub
Thanks for the help much appreciated,
MRD
Last edited: