Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 31
Default How to delete rows in visual basic

Hello,
I would like to make a code in visual basic for deleting all rows except the
rows which have a value of 1 in collum D. Thanks for helping me!

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,420
Default How to delete rows in visual basic


Public Sub DeleteDuplicateRowsUsingAutofilter()
Dim cRows As Long
Dim rng As Range

'first, count the rows to operate on
cRows = Cells(Rows.Count, TestColumn).End(xlUp).Row

'apply the autofilter for al matching cells
Columns("D").AutoFilter Field:=1, Criteria1:=1, Operator:=xlAnd

'we now have only matching rows visible, so we can
'delete these matching rows
Set rng = Range("D2").Resize(cRows - 1)
On Error Resum Next
Set rng = rng.SpecialCells(xlCellTypeVisible).EntireRow.Dele te
On Error Goto 0
If Not rng Is Nothing Then rng.EntireRow.Delete

End Sub




--
__________________________________
HTH

Bob

"Ruben" wrote in message
...
Hello,
I would like to make a code in visual basic for deleting all rows except
the
rows which have a value of 1 in collum D. Thanks for helping me!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Visual Basic mcp201 Excel Discussion (Misc queries) 0 June 23rd 08 05:05 PM
Visual Basic Co-op 20 Excel Discussion (Misc queries) 2 June 28th 07 09:06 PM
visual basic jiwolf Excel Worksheet Functions 2 October 8th 05 09:12 PM
changing the visual basic in office 2003 to visual studio net bigdaddy3 Excel Discussion (Misc queries) 1 September 13th 05 10:57 AM
Visual Basic Help Duncan Smith Excel Discussion (Misc queries) 1 December 3rd 04 09:13 AM


All times are GMT +1. The time now is 12:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"