delete unwanted lines

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
984
Office Version
  1. 2010
Platform
  1. Windows
I have a data at A2:AJ5300 and from A2:AJ5 have some unwanted lines and again on A65:AJ68, and A128:AJ131 etc meaning they have the same interval I tried this and do not work
VBA Code:
Sub montecarlo2012()

Dim i As Long
Application.ScreenUpdating = False

       For i = 2 To 5300 Step 60
            Range("A" & i & ":AJ" & (i + 3)).Delete
       Next i

Application.ScreenUpdating = True

End Sub
you know help need it;)
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
When delete rows in a loop, ALWAYS work backwards through the range.
Otherwise, you are changing the size of the range you haven't hit yet, and things may get misaligned and missed.

Assuming your logic is correct, it would look something like:
VBA Code:
For i = 5282 to 2 Step -60
 
Upvote 0
Joe4 thank you, but do not work as expected. delete the last portion and do not delete nothing else now I tried this in order to workout a little, please your advise is so important
the point here is to show you my intervals.
VBA Code:
Sub forJoefour()
    Dim i As Long
    
    Application.ScreenUpdating = False
    
    
    Dim intervals As Variant
    intervals = Array("2:5", "65:68", "128:131", "191:194", "254:257", _
                      "317:320", "380:383", "443:446", "506:509", "569:572", _
                      "632:635", "695:698", "758:761", "821:824", "884:887", _
                      "947:950", "1010:1013", "1073:1076", "1136:1139", "1199:1202", _
                      "1262:1265", "1325:1328", "1388:1391", "1451:1454", "1514:1517", _
                      "1577:1580", "1638:1641", "1701:1704", "1764:1767", "1827:1830", _
                      "1890:1893", "1953:1956", "2016:2019", "2079:2082", "2142:2145", _
                      "2205:2208", "2268:2271", "2331:2334", "2394:2397", "2457:2460", _
                      "2518:2521", "2579:2582", "2640:2643", "2703:2706", "2766:2769", _
                      "2830:2833", "2892:2895", "2955:2958", "3018:3021", "3079:3082", _
                      "3140:3143", "3203:3206", "3266:3269", "3329:3332", "3392:3395", _
                      "3455:3458", "3518:3521", "3581:3584", "3644:3647", "3707:3710", _
                      "3769:3772", "3832:3835", "3895:3898", "3958:3961", "4021:4024", _
                      "4084:4087", "4147:4150", "4209:4212", "4269:4272", "4332:4335", _
                      "4395:4398", "4458:4461", "4521:4524", "4584:4587", "4647:4650", _
                      "4709:4712", "4772:4775", "4835:4838", "4901:4904", "4964:4967", _
                      "5027:5030", "5090:5093", "5153:5156", "5216:5219")
    
    
    For i = LBound(intervals) To UBound(intervals)
        Dim deleteRange As Range
        Set deleteRange = Range("A" & intervals(i) & ":AJ" & (CLng(intervals(i)) + 3))
        
        deleteRange.Delete Shift:=xlUp
    Next i
    
    Application.ScreenUpdating = True
End Sub
Please, let me know
 
Upvote 0
Why does your data range seem to jump 63 rows at time, then all of a sudden switch to 61?
"1577:1580", "1638:1641"
1638-1577=61

Is that intentional or is that a typo?

Is this has a constant increment of exactly 63, it makes it much easier.
 
Upvote 0
Thank you for your time Sir,<" is a mistake,"> you are right, the increment is exactly 63.
sorry about that.
 
Upvote 0
Then I believe this is actually what you need:
VBA Code:
Sub montecarlo2012()

Dim i As Long
Application.ScreenUpdating = False

       For i = 5294 To 2 Step -63
            Range("A" & i & ":AJ" & (i + 3)).Delete
       Next i

Application.ScreenUpdating = True

End Sub
 
Upvote 0
this file is copy from the HTML on the web, so I am trying to clean useless legends
 
Upvote 0
deleted only the first 4 rows the rest still there.
That is not possible if you copied my code exactly as-is.
Did you copy/paste my code, or try typing it in yourself?
Also, yuo don't have two procedures in the same workbook with the same name (I used the name you had originally).
 
Upvote 0
Hi. Yes I copied exactly as the way you posted, I insert a module. I don't have another procedures, I didn't type myself.
Thank you for your concern.
 
Upvote 0

Forum statistics

Threads
1,216,807
Messages
6,132,815
Members
449,760
Latest member
letonuslepus

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