ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   New Users to Excel (https://www.excelbanter.com/new-users-excel/)
-   -   Getting macro to run with pasted function (https://www.excelbanter.com/new-users-excel/144169-getting-macro-run-pasted-function.html)

glenn

Getting macro to run with pasted function
 
Greetings,

I am trying to remove all duplicate rows by checking the first five colums
in each row. The spreadsheet is 20 colums by 800 rows, and I am using Excel
2003.

I have tried to get Chip Pearson's DeleteDuplicatesViaFilter to run, and I'm
not having any luck. Don't have much, (if any) experience with Visual Basic.
I'm not sure where to put the range of cells I want checked. I also don't
know how to name the macro to be able to make it run. Is this the best
solution? Any help would be greatly appreciated.

Here is the first part of his code:

Function DeleteDuplicatesViaFilter(ColumnRangeOfDuplicates As Range) As Long
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''
' DeleteDuplicatesViaFilter
' This function uses Advanced Filter to remove duplicate records from
' the rows spanned by ColumnRangeOfDuplicates. A row is considered to
' be a duplicate of another row if the columns spanned by
ColumnRangeOfDuplictes
' are equal. Columns outside of those spanned by ColumnRangeOfDuplicates
' are not tested. The function returns the number of rows deleted, including
' 0 if there were no duplicates, or -1 if an error occurred, such as a
' protected sheet or a ColumnRangeOfDuplicates range with multiple areas.
' Note that Advanced Filter considers the first row to be the header row
' of the data, so it will never be deleted.
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''

Dim DeleteRange As Range
Dim Rng As Range
Dim SaveCalc As Long
Dim SaveEvents As Long
Dim SaveUpdating As Long
Dim BeginRowCount As Long
Dim EndRowCount As Long

--
Thanks, Glenn

Bernie Deitrick

Getting macro to run with pasted function
 
Glenn,

You need to call the function from a subroutine. The example below works to
eliminate duplicates based on values in the first 5 columns, and assumes
that you have labels in row 1, and no gaps in your data set:

Sub TestForGlenn()
MsgBox "The function deleted " & _
DeleteDuplicatesViaFilter( _
Intersect(Range("A:E"), Range("A1").CurrentRegion)) & _
" records."
End Sub

Function DeleteDuplicatesViaFilter(ColumnRangeOfDuplicates As Range) As Long
'rest of function code here....


Simply run the macro 'TestForGlenn'

HTH,
Bernie
MS Excel MVP


"Glenn" wrote in message
...
Greetings,

I am trying to remove all duplicate rows by checking the first five colums
in each row. The spreadsheet is 20 colums by 800 rows, and I am using
Excel
2003.

I have tried to get Chip Pearson's DeleteDuplicatesViaFilter to run, and
I'm
not having any luck. Don't have much, (if any) experience with Visual
Basic.
I'm not sure where to put the range of cells I want checked. I also don't
know how to name the macro to be able to make it run. Is this the best
solution? Any help would be greatly appreciated.

Here is the first part of his code:

Function DeleteDuplicatesViaFilter(ColumnRangeOfDuplicates As Range) As
Long
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''
' DeleteDuplicatesViaFilter
' This function uses Advanced Filter to remove duplicate records from
' the rows spanned by ColumnRangeOfDuplicates. A row is considered to
' be a duplicate of another row if the columns spanned by
ColumnRangeOfDuplictes
' are equal. Columns outside of those spanned by ColumnRangeOfDuplicates
' are not tested. The function returns the number of rows deleted,
including
' 0 if there were no duplicates, or -1 if an error occurred, such as a
' protected sheet or a ColumnRangeOfDuplicates range with multiple areas.
' Note that Advanced Filter considers the first row to be the header row
' of the data, so it will never be deleted.
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''

Dim DeleteRange As Range
Dim Rng As Range
Dim SaveCalc As Long
Dim SaveEvents As Long
Dim SaveUpdating As Long
Dim BeginRowCount As Long
Dim EndRowCount As Long

--
Thanks, Glenn




glenn

Getting macro to run with pasted function
 
Bernie,

Thank you so much, that did the trick.
--
Glenn


"Bernie Deitrick" wrote:

Glenn,

You need to call the function from a subroutine. The example below works to
eliminate duplicates based on values in the first 5 columns, and assumes
that you have labels in row 1, and no gaps in your data set:

Sub TestForGlenn()
MsgBox "The function deleted " & _
DeleteDuplicatesViaFilter( _
Intersect(Range("A:E"), Range("A1").CurrentRegion)) & _
" records."
End Sub

Function DeleteDuplicatesViaFilter(ColumnRangeOfDuplicates As Range) As Long
'rest of function code here....


Simply run the macro 'TestForGlenn'

HTH,
Bernie
MS Excel MVP


"Glenn" wrote in message
...
Greetings,

I am trying to remove all duplicate rows by checking the first five colums
in each row. The spreadsheet is 20 colums by 800 rows, and I am using
Excel
2003.

I have tried to get Chip Pearson's DeleteDuplicatesViaFilter to run, and
I'm
not having any luck. Don't have much, (if any) experience with Visual
Basic.
I'm not sure where to put the range of cells I want checked. I also don't
know how to name the macro to be able to make it run. Is this the best
solution? Any help would be greatly appreciated.

Here is the first part of his code:

Function DeleteDuplicatesViaFilter(ColumnRangeOfDuplicates As Range) As
Long
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''
' DeleteDuplicatesViaFilter
' This function uses Advanced Filter to remove duplicate records from
' the rows spanned by ColumnRangeOfDuplicates. A row is considered to
' be a duplicate of another row if the columns spanned by
ColumnRangeOfDuplictes
' are equal. Columns outside of those spanned by ColumnRangeOfDuplicates
' are not tested. The function returns the number of rows deleted,
including
' 0 if there were no duplicates, or -1 if an error occurred, such as a
' protected sheet or a ColumnRangeOfDuplicates range with multiple areas.
' Note that Advanced Filter considers the first row to be the header row
' of the data, so it will never be deleted.
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''

Dim DeleteRange As Range
Dim Rng As Range
Dim SaveCalc As Long
Dim SaveEvents As Long
Dim SaveUpdating As Long
Dim BeginRowCount As Long
Dim EndRowCount As Long

--
Thanks, Glenn






All times are GMT +1. The time now is 06:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com