Get unique values from a 2d range?

Rick, your code works. I have 9 columns. I didn't change the data between attempts.

Dim Rng As Range, V As Variant, Data As Variant
Data = Range("C3:K4")
With CreateObject("Scripting.Dictionary")
For Each V In Data
If Len(V) Then .Item(V) = 1
Next
Range("J15").Resize(.Count) = Application.Transpose(.Keys)
End With
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Data = Range("C3:K4")
The reason igold's code did not work for you when you made the above change is that was not the only change you needed to make for his code (my code works slightly differently, so it wasn't a problem for you there). In igold's code is this line of code...

For i = 1 to 4

The 4 is the number of columns... when you changed the number of columns in the range being processed, you needed to account for it in the above line of code as well. If you had changed that line to this...

For i = 1 to 9

along with the range change, then his code would have worked for you as well.
 
Upvote 0
Errant post.
 
Last edited:
Upvote 0
@Rick,

You took care of the blanks with this line...

Code:
If Len(V) Then .Item(V) = 1

Is that correct...
Yes... if there length was 0 (blank, no text), that is the same as being False and if the length was greater than 0, VB considers that True (to VB, True is actually determined by it being Not False, or with numbers, Not 0).
 
Last edited:
Upvote 0
Yes... if there length was 0 (blank, no text), that is the same as being False and if the length was greater than 0, VB considers that True (to VB, True is actually determined by it being Not False, or with numbers, Not 0).

@Rick,

Yes I realized that quickly after I posted the question so I deleted it. However what you have said here is what I had originally done in the post in which you and Mark are discussing .HasFormula. I used this logic on .Formula in my code and Mark had changed it to .HasFormula.
 
Upvote 0
@Rick,

However what you have said here is what I had originally done in the post in which you and Mark are discussing .HasFormula.
You really should have posted your comment in the other thread where I think your comment would have been more relevant.


O.T.
I used this logic on .Formula in my code and Mark had changed it to .HasFormula.
You cannot use that shortcut with the Formula property because it contains a text String value only, not a Boolean. If you wanted to test if the cell has a formula or not using the Formula property, you would have to test its length.
 
Last edited:
Upvote 0
I can mark this thread solved if you tell me how...
This forum does not have a way to do that... most threads are assumed closed when the original poster posts a final "thank you" message which indicates the problem was solved.
 
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