Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default Remove all duplicates and return highest value in new row

Hi

I am looking to locate all duplicates of a descriptor in column a, remove,
and create a new row with just the descriptor and the highest value in column
b.
For example

col a col b
generice code 1 000123456
generice code 1 000123678
generice code 1 000123910

Returns:
generice code 1 000123910

....and removes all other lines

many thanks

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Remove all duplicates and return highest value in new row

Try this small macro:

Sub nikky()
Dim v1 As String, v2 As Long
n = Cells(Rows.Count, 1).End(xlUp).Row
For i = n To 1 Step -1
v1 = Cells(i, 1).Value
v2 = Cells(i, 2).Value
For j = n To 1 Step -1
If Cells(j, 1).Value = v1 And Cells(j, 2).Value v2 Then
Cells(i, 1).EntireRow.Delete
GoTo nextone
End If
Next
nextone:
Next
End Sub

So if we start with:

cat 1
mouse 1
dog 66
mouse 4
dog 5
mouse 2
cat 34
dog 3


the macro will produce:

dog 66
mouse 4
cat 34



--
Gary''s Student - gsnu200828


"Nikkynock" wrote:

Hi

I am looking to locate all duplicates of a descriptor in column a, remove,
and create a new row with just the descriptor and the highest value in column
b.
For example

col a col b
generice code 1 000123456
generice code 1 000123678
generice code 1 000123910

Returns:
generice code 1 000123910

...and removes all other lines

many thanks

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default duplicates

hi

cannot run as vba debug highlights v2 = Cells(i, 2).Value as the issue.
Being completely illiterate in vba, i'm not sure what how to fix

thanks
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default duplicates

If the v2 line fails, that probably means the the values in column B are not
real numbers, they may be Text instead.

We either need to insure that they are numbers or find a way to make them
numbers.
--
Gary''s Student - gsnu200828


"nikkynock" wrote:

hi

cannot run as vba debug highlights v2 = Cells(i, 2).Value as the issue.
Being completely illiterate in vba, i'm not sure what how to fix

thanks

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default duplicates

hi
think you are right - the data is barcode data from a sales info provider.
the data looks like this when first imported into excel: 5.01111E+12. I
change cells to 'number' with 0 decimal points to show the actual number (in
this example .01111E+12 = 5011111805106), but i guess this is still not seen
as a number in the cell? anything i can do to convert - i tried text to
columns but this has not helped?

"Gary''s Student" wrote:

If the v2 line fails, that probably means the the values in column B are not
real numbers, they may be Text instead.

We either need to insure that they are numbers or find a way to make them
numbers.
--
Gary''s Student - gsnu200828


"nikkynock" wrote:

hi

cannot run as vba debug highlights v2 = Cells(i, 2).Value as the issue.
Being completely illiterate in vba, i'm not sure what how to fix

thanks



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default duplicates

5011111805106 is a valid number. Are any values more than 15 digits??
--
Gary''s Student - gsnu200828


"nikkynock" wrote:

hi
think you are right - the data is barcode data from a sales info provider.
the data looks like this when first imported into excel: 5.01111E+12. I
change cells to 'number' with 0 decimal points to show the actual number (in
this example .01111E+12 = 5011111805106), but i guess this is still not seen
as a number in the cell? anything i can do to convert - i tried text to
columns but this has not helped?

"Gary''s Student" wrote:

If the v2 line fails, that probably means the the values in column B are not
real numbers, they may be Text instead.

We either need to insure that they are numbers or find a way to make them
numbers.
--
Gary''s Student - gsnu200828


"nikkynock" wrote:

hi

cannot run as vba debug highlights v2 = Cells(i, 2).Value as the issue.
Being completely illiterate in vba, i'm not sure what how to fix

thanks

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default removing duplicates and returning highest value in new row

the max number of digits in the string is 13 - any ideas?
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
return next highest number in range Code Numpty Excel Worksheet Functions 6 April 21st 11 08:19 PM
Return highest number or a blank if 0 Toney Excel Discussion (Misc queries) 6 October 8th 08 06:19 PM
2 rows, highest No in row 1, then highest number in row 2 relating to that column, possible duplicates John Excel Worksheet Functions 3 August 11th 06 04:34 AM
Summing & return highest value PSU35 New Users to Excel 2 May 31st 06 07:39 PM
How do I return the highest value in a range of cells pjs83 Excel Worksheet Functions 5 July 6th 05 09:25 PM


All times are GMT +1. The time now is 06:16 PM.

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

About Us

"It's about Microsoft Excel"