Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

VBA unique formula with variable

I’m having a really hard time setting the correct formula in VBA to output a list of unique values in a list.

    Dim lastRow As Long
    With ActiveSheet
        lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    End With
    Range("B1").Select
    ActiveCell.Formula2R1C1 = "=UNIQUE(RC[-1]:" & lastRow & ")"

Pretty simple what I’m trying to do. Just use the range from cell A1 to the last row in the that column and push it to the unique formula.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

A1 notation:

Range("B1").Formula2 = "=UNIQUE(A1:A" & lastRow & ")"

R1C1 notation:

Range("B1").Formula2R1C1 = "=UNIQUE(RC[-1]:R[" & lastRow & "]C[-1])"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading