Get unique values from a 2d range?

The code stops short. There is indeed one blank cell, but it doesn't finish the column. The data is below, where Main Shaft Extreme is in the 1st cell of the 1st row, and all the rest are in the 2nd row, with a blank cell separating them, indicated with "blankcell".

Main Shaft Extreme
Main Gearbox (gears/bearings) Fatigue blankcell Gearbox Foundation Fatigue blankcell Main Shaft Fatigue Generator Mounts Fatigue blankcell Generator Flex Couplings & HSS Fatigue
 
Last edited:
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Here is how I would write the macro (output to Column F)...
Code:
Sub UniquesWithinA1D10()
  Dim Rng As Range, V As Variant, Data As Variant
  Data = Range("A1:D10")
  With CreateObject("Scripting.Dictionary")
    For Each V In Data
      If Len(V) Then .Item(V) = 1
    Next
    Range("F1").Resize(.Count) = Application.Transpose(.Keys)
  End With
End Sub
 
Upvote 0
@Rick,

Actually, you did write the code. I tried to make the adjustment for the additional values in the range. When I was testing, I noticed that the Ubound of the array was correct yet it was not outputting all the values to the column. I was short one value, which is why I added 1 to Ubound(arr).

Could you explain to me why this is happening.

Regards,

igold
 
Upvote 0
The code stops short. There is indeed one blank cell, but it doesn't finish the column. The data is below, where Main Shaft Extreme is in the 1st cell of the 1st row, and all the rest are in the 2nd row, with a blank cell separating them, indicated with "blankcell".

Main Shaft Extreme
Main Gearbox (gears/bearings) Fatigue blankcell Gearbox Foundation Fatigue blankcell Main Shaft Fatigue Generator Mounts Fatigue blankcell Generator Flex Couplings & HSS Fatigue

How many columns is that? It is hard to tell from your description. It looks like more than 4 columns, it looks like 7 columns...

igold
 
Last edited:
Upvote 0
@Rick,

Actually, you did write the code. I tried to make the adjustment for the additional values in the range. When I was testing, I noticed that the Ubound of the array was correct yet it was not outputting all the values to the column. I was short one value, which is why I added 1 to Ubound(arr).

Could you explain to me why this is happening.
The problem (it is not actually a "problem" as such) happens when you assigned .keys to arr and then worked only from the arr array. The Keys property of a dictionary is a zero-based array so UBound for it is one less than the actual number of elements in the array, hence, you had to add one to account for that zero-eth element. I avoided that problem by not assigning it to an array but, rather, working directly with the dictionary object itself... I transposed the dictionary's Keys property directly and used the dictionary's Count property to find out how many keys there were.
 
Upvote 0
Makes sense, thanks. So the code as written should work.

If the OP is having issues, I suspect that the number of columns in his array is more than the four he indicated in the original post.

As always, thanks for your time.

igold
 
Upvote 0
Makes sense, thanks. So the code as written should work.

If the OP is having issues, I suspect that the number of columns in his array is more than the four he indicated in the original post.
We can only code for what the posters tell us which is why I always try to remember to tell them (when appropriate) not to simplify their questions for us as that will only get them great answers to a question they don't have and for which they really don't care.
 
Upvote 0
Yes, 7 columns, but I changed the range in your code to engulf it. Should it not work?
It should... why don't you show us the code you now have so that we can see if any other issues may have been raised.
 
Upvote 0
Let's see the changes you made.

I just made change to account for 7 columns and the code worked.
 
Upvote 0

Forum statistics

Threads
1,215,446
Messages
6,124,900
Members
449,194
Latest member
JayEggleton

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top