VBA - Delete a range of TEXT rows and move Numbers to preceding row

MRDecarte

New Member
Joined
May 24, 2014
Messages
20
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

 
Last edited:

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,214,943
Messages
6,122,369
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top