Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-28-2016, 09:27 PM
tomlam tomlam is offline count and delete row Windows 7 64bit count and delete row Office 2007
Advanced Beginner
count and delete row
 
Join Date: Oct 2012
Posts: 33
tomlam is on a distinguished road
Default count and delete row

Dear Sir



We need your help
Each day we do thousand of sheets like as follow workdone.
We need to count the latest 15 records. For more than 15 records, we delete as
Yellow color row. That is the old record we need to delete. For less than 15 records,
We delete the yellow color row. After VBA code, The final result should be same as file named after. Attached pls find two file name before ,after

The vba code don’t work…pls help..many thanks

lastRow = Cells(Rows.Count, 1).End(xlUp).Row
For z = 1 To lastrow
If (Cells(z, ("c"))) = "" Then Cells(z, ("c")).EntireRow.Clear
Next z

Many Thanks
Tom
Attached Files
File Type: xls AFTER.xls (37.0 KB, 15 views)
File Type: xls BEFORE.xls (32.0 KB, 14 views)
Reply With Quote
  #2  
Old 09-29-2016, 11:32 AM
charlesdh charlesdh is offline count and delete row Windows 7 32bit count and delete row Office 2010 32bit
Expert
 
Join Date: Apr 2014
Location: Mississippi
Posts: 382
charlesdh is on a distinguished road
Default

Hi,
How do you determine the "Old Record".
Reply With Quote
  #3  
Old 09-29-2016, 12:17 PM
NoSparks NoSparks is offline count and delete row Windows 7 64bit count and delete row Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 831
NoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really nice
Default

I believe this does what you're asking, although it doesn't match your after file.
Code:
Sub tomlam()
' remove rows with blank "C" and limit to 15

    Dim lr As Long
    Dim r As Long
    Dim i As Integer

With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With

'delete rows where C is blank
Range("C1", Cells(Rows.Count, "C").End(xlUp)).SpecialCells(xlBlanks).EntireRow.Delete

'limit to 15
lr = Cells(Rows.Count, "C").End(xlUp).Row
For r = lr To 2 Step -1
    If Cells(r, "C").Value = "total export" Then
        i = 0
    Else
        i = i + 1
    End If
    If i > 15 Then Rows(r).Delete
Next r

With Application
    .ScreenUpdating = True
    .Calculation = xlCalculationAutomatic
End With

End Sub
Reply With Quote
  #4  
Old 09-29-2016, 03:54 PM
tomlam tomlam is offline count and delete row Windows 7 64bit count and delete row Office 2007
Advanced Beginner
count and delete row
 
Join Date: Oct 2012
Posts: 33
tomlam is on a distinguished road
Default

Many Thanks to Nosparks. It is great ...solved....
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
count and delete row Getting the Count formula to count all rows Jennifer Murphy Word Tables 11 08-23-2016 09:37 PM
How to Delete the same watermark that are in 300 slides. I cant dare to manually delete. yeshwanthkota111 PowerPoint 0 09-05-2015 10:03 AM
count and delete row Delete starting number *) and delete Unneeded data in series frustrated teacher Word VBA 5 12-07-2014 06:53 PM
Delete option greyed out when trying to delete row 1 tpcervelo Excel 2 11-15-2011 06:48 AM
delete email message via blackberry and have it delete on my pop3 and my outlook Iamthestorm Outlook 2 10-28-2010 12:21 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:03 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft