vba delete Row based on

panyagak

Active Member
Joined
Feb 24, 2017
Messages
299
hi everyone.

I need to clean up my long data in column A.

The word "DIM" STARTS the next set of data downwards AND BEFORE IT is a Number.
eg.
DIM
2236.2
DIM
Vlogger
DIM. etc etc

so I need to delete Rows just before DIM in instances where IT IS NOT A VALUE. Eg above, Delete Vlogger Row since its not a number.

the column A is long down..

Thanks
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
1702561664203.png

1702561697044.png

VBA Code:
Dim Wb As Workbook
Dim WsIn As Worksheet
Dim LastRow As Long
Dim Aloop As Long
Dim DIMrow As Boolean

Sub DeleteNonNum()
    Set Wb = ThisWorkbook
    Set WsIn = Wb.Worksheets("Sheet1")
    LastRow = WsIn.Cells(WsIn.Rows.Count, "A").End(xlUp).Row
    DIMrow = False
 
    For Aloop = LastRow To 1 Step -1
       If DIMrow = True Then
           If Not IsNumeric(WsIn.Cells(Aloop, 1).Value) Then
               WsIn.Rows(Aloop).Delete Shift:=xlUp
           End If
           DIMrow = False
       Else
           If WsIn.Cells(Aloop, 1) = "DIM" Then
               DIMrow = True
           End If
       End If
    Next Aloop
 
End Sub
 
Upvote 0
Solution
View attachment 103499
View attachment 103500
VBA Code:
Dim Wb As Workbook
Dim WsIn As Worksheet
Dim LastRow As Long
Dim Aloop As Long
Dim DIMrow As Boolean

Sub DeleteNonNum()
    Set Wb = ThisWorkbook
    Set WsIn = Wb.Worksheets("Sheet1")
    LastRow = WsIn.Cells(WsIn.Rows.Count, "A").End(xlUp).Row
    DIMrow = False
 
    For Aloop = LastRow To 1 Step -1
       If DIMrow = True Then
           If Not IsNumeric(WsIn.Cells(Aloop, 1).Value) Then
               WsIn.Rows(Aloop).Delete Shift:=xlUp
           End If
           DIMrow = False
       Else
           If WsIn.Cells(Aloop, 1) = "DIM" Then
               DIMrow = True
           End If
       End If
    Next Aloop
 
End Sub

nemmi69

thanks a lot...it worked
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,977
Members
449,095
Latest member
Mr Hughes

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