Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]() 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! |
#4
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
It is the same in VB as it does in VBA, you just need to get an application
object. -- __________________________________ HTH Bob "Varne" wrote in message ... Hi Ruben Sorry for question for question. Are you talking about Excel rows to be deleted by VB? If could you breifly tell me how to write 1 on Range("A1") on an Excel sheet using VB 6 not VBA? "Bob Phillips" wrote: 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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Visual Basic | Excel Discussion (Misc queries) | |||
Visual Basic | Excel Discussion (Misc queries) | |||
visual basic | Excel Worksheet Functions | |||
changing the visual basic in office 2003 to visual studio net | Excel Discussion (Misc queries) | |||
Visual Basic Help | Excel Discussion (Misc queries) |