Visual Basic (VB and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

 

Please read the DISCLAIMER.

Here is an INDEX to all the procedures.

You will probably need one copy of my GLOBAL DECLARATIONS.



Public Function lngDeleteDuplicateRows(rngTbl As Range, intCount As Integer) As Long
' Procedure :   lngDeleteDuplicateRows
' Description:  Delete adjacent rows of a table that are identical in text content.
' By:           Chris Greaves Inc.
' Inputs:       RANGE of rows, INTEGER count of rows.
' Returns:      LONG count of rows deleted.
' Assumes:      None.
' Side Effects: None.
' Tested:       By the calls below.
    Dim lngCount As Long
    lngCount = 0
' When we delete elements of a collection, we change the structure of the collection.
'   So, lets loop by row index, backwards from the top.
    If rngTbl.Rows.Count > 1 Then
        Dim strOld As String ' Holds the latest row we are comparing
        strOld = strTextOfRow(rngTbl.Rows(1).Range, intCount)
        Dim intRow As Integer
        For intRow = rngTbl.Rows.Count - 1 To 1 Step -1
            Dim strText As String
            strText = strTextOfRow(rngTbl.Rows(intRow).Range, intCount)
            If strOld = strText Then
                lngCount = lngCount + 1
                rngTbl.Rows(intRow).Delete
            Else
                strOld = strText
            End If
        Next intRow
    Else ' only one row, therefore no duplicates
    End If
    lngDeleteDuplicateRows = lngCount
'Sub TESTlngDeleteDuplicateRows()
'Documents.Add
'ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=8, NumColumns:=8
'MsgBox lngDeleteDuplicateRows(Selection.Tables(1).Range)
'End Sub
End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Thursday, November 15, 2001

 

 

Hosted by www.Geocities.ws

1

Visual Basic (VB and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

 

Please read the DISCLAIMER.

Here is an INDEX to all the procedures.

You will probably need one copy of my GLOBAL DECLARATIONS.

Public Function lngDeleteDuplicateRows(rngTbl As Range, intCount As Integer) As Long
' Procedure :   lngDeleteDuplicateRows
' Description:  Delete adjacent rows of a table that are identical in text content.
' By:           Chris Greaves Inc.
' Inputs:       RANGE of rows, INTEGER count of rows.
' Returns:      LONG count of rows deleted.
' Assumes:      None.
' Side Effects: None.
' Tested:       By the calls below.
    Dim lngCount As Long
    lngCount = 0
' When we delete elements of a collection, we change the structure of the collection.
'   So, lets loop by row index, backwards from the top.
    If rngTbl.Rows.Count > 1 Then
        Dim strOld As String ' Holds the latest row we are comparing
        strOld = strTextOfRow(rngTbl.Rows(1).Range, intCount)
        Dim intRow As Integer
        For intRow = rngTbl.Rows.Count - 1 To 1 Step -1
            Dim strText As String
            strText = strTextOfRow(rngTbl.Rows(intRow).Range, intCount)
            If strOld = strText Then
                lngCount = lngCount + 1
                rngTbl.Rows(intRow).Delete
            Else
                strOld = strText
            End If
        Next intRow
    Else ' only one row, therefore no duplicates
    End If
    lngDeleteDuplicateRows = lngCount
'Sub TESTlngDeleteDuplicateRows()
'Documents.Add
'ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=8, NumColumns:=8
'MsgBox lngDeleteDuplicateRows(Selection.Tables(1).Range)
'End Sub
End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Thursday, November 15, 2001

 

 

Hosted by www.Geocities.ws

1