VBA delet avery 11 value if not text( or if number is true), and loop on

Gokuba

New Member
Joined
Aug 6, 2018
Messages
19
Hi , my question is how to loop through the range( column) and delete every 11th value if it is a number, or if it is not a text( both works).

Product
product name
123
123
1234
435
564
234
345
3245
NONO
234

So here on the 11th row, I have a text I would like it to be deleted ( whole row) if not text then loop skips.

Trying with my code but it doesn't work:

Code:
Sub deletenthifnumber()




Dim LastRow As Long
Dim x As Long






    LastRow = .Cells(.Rows.Count, "H").End(xlUp).row


    For x = LastRow To 1 Step -1 ' allways loop backwards when deleting rows
        If Not IsNumeric(Range("a" & x).Value Then
            .Rows(x).Delete
        End If
    Next x
End With


End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
PS. the oced above is not mine I just tailored it to my pruposes.
 
Last edited by a moderator:
Upvote 0
First you say
delete every 11th value if it is a number, or if it is not a text( both works).
then you say
So here on the 11th row, I have a text I would like it to be deleted
These 2 statements contradict each other.
Which is correct?

Also please do not quote entire posts as it makes the thread harder to navigate & is normally unnecessary.
 
Upvote 0
Well, I reckoned that if I know the code I can freely change it, but what I am after is = if it is a number value. So in my range("A:
A") if I start from the top and loop every 7th row if the value is a number I would like to delete a whole row, and then continue with the row below =y and so on. Does it make sense?
 
Upvote 0
How about
Code:
Sub delrws()
   Dim Rng As Range
   Dim i As Long
   
   With Sheets("Sheet1")
      For i = 7 To .Range("A" & Rows.Count).End(xlUp).Row Step 7
         If IsNumeric(.Range("A" & i).Value) Then
            If Rng Is Nothing Then Set Rng = .Rows(i) Else Set Rng = Union(Rng, .Rows(i))
         End If
      Next i
      If Not Rng Is Nothing Then Rng.Delete
   End With
End Sub

Word of warning
IsNumeric has certain flaws which you can read about here. So it depends on your data as to whether it's suitable to use.
 
Last edited:
Upvote 0
WORKS LIKE A CHARM, THANK YOU. Now I need to go back and recode to understand it, still works splendidly.
THANK YOU
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,442
Members
449,083
Latest member
Ava19

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