Excel error 1004 "Unable to get .... property of WorksheetFunction class"

Persl

New Member
Joined
Jun 29, 2020
Messages
14
Office Version
  1. 365
Platform
  1. Windows
Good day

I try to get an unique list to use it on dropdown list but the below code give me an error


VBA Code:
Sub CopyUniqueValues()
    Dim lastRow As Long
    Dim uniqueValues As Variant
    Dim i As Long
    Sheets("histor").Select
    ' Find the last row in column C of histor
    lastRow = Sheets("histor").Cells(Rows.Count, "k").End(xlUp).Row
    
    ' Get the unique values from column C of Sheet1
    uniqueValues = WorksheetFunction.Unique(Sheets("histor").Range("k1:k100"))
    
    ' Paste the unique values into cell D4 of Sheet2
    For i = 1 To UBound(uniqueValues)
        Sheets("DAILY OPS REPORT8").Range("IB4").Offset(i - 1, 0).Value = uniqueValues(i, 1)
    Next i
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Which line was highlighted, in debug code window?
This line of code
For
Sheets("DAILY OPS REPORT8").Range("IB4").Offset(i - 1, 0).Value = ...
Next
this cell value is always last "i" of uniqueValue array , not a list (from 1 to i)
 
Upvote 0
uniqueValues = WorksheetFunction.Unique(Sheets("histor").Range("k1:k100"))

this code
 
Upvote 0
I try it as below with same issue

VBA Code:
    ' Get the unique values from column K of histor
    uniqueValues = WorksheetFunction.Unique(Sheets("histor").Range("K4:K" & lastRow))
 
Upvote 0
Unique function is in 365, is it array function? (I am not using 365)
I suppose that VBA code does not allow this:
single variant varriable = array function
Using dictionary instead, I guess.
 
Upvote 0
Unique function is in 365, is it array function? (I am not using 365)
I suppose that VBA code does not allow this:
single variant varriable = array function
Using dictionary instead, I guess.

Iam using office16 not 365 for time bening
 
Upvote 0

Forum statistics

Threads
1,223,157
Messages
6,170,419
Members
452,325
Latest member
BlahQz

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