VBA code help to get ranges correct

steve400243

Active Member
Joined
Sep 15, 2016
Messages
429
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello, I want to be able to use this code, or a similar one, to search sheet 1 starting in A2 and searching the entire column for uniques. Then the resulting list to "ANALYSIS" Sheet starting in U4. Thanks for all help provided.

VBA Code:
Option Explicit
Sub GetUniques()
Dim d As Object, c As Variant, i As Long, lr As Long
Set d = CreateObject("Scripting.Dictionary")
lr = Cells(Rows.Count, 1).End(xlUp).Row
c = Range.Sheet1("A2:A" & lr)
For i = 1 To UBound(c, 1)
  d(c(i, 1)) = 1
Next i
Range.ANALYSIS("U4").Resize(d.Count) = Application.Transpose(d.keys)
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Are sheet1 & Analysis sheet names or sheet codenames?
 
Upvote 0
Sorry - those are the sheet tab names. Sheet 2 was renamed to ANALYSIS.
 
Upvote 0
Ok, in that case try
VBA Code:
Sub GetUniques()
   Dim d As Object, c As Variant, i As Long, lr As Long
   Set d = CreateObject("Scripting.Dictionary")
   lr = Cells(Rows.Count, 1).End(xlUp).Row
   c = Sheets("Sheet1").Range("A2:A" & lr).Value2
   For i = 1 To UBound(c, 1)
     d(c(i, 1)) = Empty
   Next i
   Sheets("ANALYSIS").Range("U4").Resize(d.Count) = Application.Transpose(d.Keys)
End Sub
 
Upvote 0
Thank you Fluff - This will work for my needs. I appreciate you looking at it. So much to learn.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
It is leaving a blank row in the results? any idea why it would do that?

CMDUCNCT429958
CMDUCNCT429988
CMDUCNCT427114
CMDUCNCT427129
 
Upvote 0
You've probably got a blank row in the data ;)
Make this change
VBA Code:
   For i = 1 To UBound(c, 1)
     If c(i, 1) <> "" Then d(c(i, 1)) = Empty
   Next i
 
Upvote 0
Ah I see that now, oops. Any way to have it skip blank rows? As there will be some in the column.
 
Upvote 0
You've probably got a blank row in the data ;)
Make this change
VBA Code:
   For i = 1 To UBound(c, 1)
     If c(i, 1) <> "" Then d(c(i, 1)) = Empty
   Next i

Thanks Again, Really appreciate your help.
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,557
Latest member
richa mishra

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