Forum

DELETING OF ROWS WI...
 
Notifications
Clear all

DELETING OF ROWS WITH VALUES BELOW A CERTAIN RANGE

10 Posts
3 Users
0 Reactions
61 Views
(@mr-motha)
Posts: 7
Active Member
Topic starter
 

Hi,

Please assist with a macro that can help with deleting entire rows for cells with a value amount of exactly 0 in column "A"

Rgds.

 
Posted : 13/01/2019 7:09 am
(@sunnykow)
Posts: 1417
Noble Member
 

Hi Themba

Try this

Sub DelRows()
Dim LastRow As Long
Dim i As Long

LastRow = Cells(Rows.Count, "A").End(xlUp).Row

Application.ScreenUpdating = False
For i = LastRow To 1 Step -1
If Cells(i, 1) = 0 Then
Rows(i).Delete Shift:=xlUp
End If
Next
Application.ScreenUpdating = True
End Sub

Sunny

 
Posted : 13/01/2019 11:58 am
(@david_ng)
Posts: 310
Reputable Member
 

How to modified teh VBA if this cell range contains multiple criteria , say " ABC co" , "Dept", "Allocation Code" , "Currency","Country" 

and to be deleted by macro

 
Posted : 14/01/2019 8:42 pm
(@sunnykow)
Posts: 1417
Noble Member
 

Are you referring to column A with multiple criteria or multiple column with criteria?

Either way you can use OR to check multiple criteria.

Example:

If Cells(i,1)="X" or Cells(i,2)="Y" OR Cells(i,3)="Z" Then

to delete the row if the any of the cells contains X, Y or Z etc

If all the criteria is in a single column, then you should match cell by cell against a list of criteria instead of using multiple ORs

You can post your file with enough examples for us to understand better what you wanted.

 
Posted : 14/01/2019 9:46 pm
(@david_ng)
Posts: 310
Reputable Member
 

Tks Sunny , it work perfectly!

 
Posted : 14/01/2019 11:15 pm
(@david_ng)
Posts: 310
Reputable Member
 

Sub DelRows()
 Dim LastRow As Long
 Dim i As Long

LastRow = Cells(Rows.Count, "A").End(xlUp).Row

Application.ScreenUpdating = False
 For i = LastRow To 1 Step -1
 If Cells(i, 1) = any text { ie  string value] or Cels(i,1) = blank row or  Then
    Rows(i).Delete Shift:=xlUp
 End If
 Next
 Application.ScreenUpdating = True
 End Sub

 

How to re-write the macro if Column A data contact any string value or blank row,  then delete , leaving only date value in the column A data

 
Posted : 14/01/2019 11:36 pm
(@sunnykow)
Posts: 1417
Noble Member
 

Try

If Not IsDate(Cells(i,1)) Then

 
Posted : 15/01/2019 2:11 am
(@david_ng)
Posts: 310
Reputable Member
 

Tks will try

 
Posted : 15/01/2019 2:54 am
(@david_ng)
Posts: 310
Reputable Member
 

I tried and confirm the Syntex work. Thanks again Sunny..

If Not IsDate(Cells(i,1)) Then

 
Posted : 15/01/2019 5:02 am
(@sunnykow)
Posts: 1417
Noble Member
 

OK No problem.

 
Posted : 15/01/2019 11:08 am
Share: