VBA for Adding Unique Values in Row to Column D

BraytonM

New Member
Joined
Jul 25, 2021
Messages
24
Office Version
  1. 365
Hello all,

I am looking for a VBA to do the following: add the unique values in rows that aren't blank to column D. Column C adds up the unique values per row (range R:AQ) and I have a macro that adds X values above based on that value.

I have attached a before and after of what I would like the macro to do. Hopefully, y'all can help me!
 

Attachments

  • Before.PNG
    Before.PNG
    38.4 KB · Views: 17
  • After.PNG
    After.PNG
    40.2 KB · Views: 14

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try this:

VBA Code:
Sub AddUniqueValues()
  Dim a As Range, dic As Object, j As Long
  For Each a In Range("A2", Range("A" & Rows.Count).End(3)).SpecialCells(xlCellTypeConstants)
    Set dic = CreateObject("Scripting.Dictionary")
    For j = 4 To Cells(a.Row, Columns.Count).End(1).Column
      If Cells(a.Row, j) <> "" Then dic(Cells(a.Row, j).Value) = Empty
    Next
    a.Offset(dic.Count * -1, 2).Resize(dic.Count).Value = Application.Transpose(dic.keys)
  Next
End Sub
 
Upvote 0
Try this:

VBA Code:
Sub AddUniqueValues()
  Dim a As Range, dic As Object, j As Long
  For Each a In Range("A2", Range("A" & Rows.Count).End(3)).SpecialCells(xlCellTypeConstants)
    Set dic = CreateObject("Scripting.Dictionary")
    For j = 4 To Cells(a.Row, Columns.Count).End(1).Column
      If Cells(a.Row, j) <> "" Then dic(Cells(a.Row, j).Value) = Empty
    Next
    a.Offset(dic.Count * -1, 2).Resize(dic.Count).Value = Application.Transpose(dic.keys)
  Next
End Sub
Hello @DanteAmor, I tried this and got a Run-time error 1004 error: no cells were found.
 
Upvote 0
The data structure of your test is not similar to the data structure of your example.
You can put a sample of your test data here. It would be ideal if you put them using the XL2BB tool minisheets.
 
Upvote 0
The data structure of your test is not similar to the data structure of your example.
You can put a sample of your test data here. It would be ideal if you put them using the XL2BB tool minisheets.
Perhaps so, let me download XL2BB tool minisheet and I will get back to this! Thank you so much for you help!
 
Upvote 0
I have added a mini-spreadsheet (hopefully this works haha). Please note the correct range is V2:AU and that all unique values in non-blank rows should be added to Column D. Thank you. @DanteAmor

Cell Formulas
RangeFormula
I1:N1I1=J1-1
O1O1=Timesheet!C7
V1:X1V1=$I$1
Y1:AB1Y1=$J$1
AC1:AF1AC1=$K$1
AG1:AJ1AG1=$L$1
AK1:AN1AK1=$M$1
AO1:AR1AO1=$N$1
AS1:AU1AS1=$O$1
A5A5=IF(Timesheet!AI15=0,"",Timesheet!$C$15)
B5,B15B5=IF(A5<>"","ST","")
C5,C21,C19,C17,C15,C11,C8C5=SUMPRODUCT((V5:AU5<>"")/COUNTIF(V5:AU5,V5:AU5&""))
V5V5=IF(Timesheet!H15>0,CONCAT(Timesheet!$H$5," ",Timesheet!$H$4,""),"")
W5W5=IF(Timesheet!I15>0,CONCAT(Timesheet!$I$5," ",Timesheet!$I$4,""),"")
X5X5=IF(Timesheet!J15>0,CONCAT(Timesheet!$J$5," ",Timesheet!$J$4,""),"")
Y5Y5=IF(Timesheet!K15>0,CONCAT(Timesheet!$K$5," ",Timesheet!$K$4,""),"")
Z5Z5=IF(Timesheet!L15>0,CONCAT(Timesheet!$L$5," ",Timesheet!$L$4,""),"")
AA5AA5=IF(Timesheet!M15>0,CONCAT(Timesheet!$M$5," ",Timesheet!$M$4,""),"")
AB5AB5=IF(Timesheet!N15>0,CONCAT(Timesheet!$N$5," ",Timesheet!$N$4,""),"")
AC5AC5=IF(Timesheet!O15>0,CONCAT(Timesheet!$O$5," ",Timesheet!$O$4,""),"")
AD5AD5=IF(Timesheet!P15>0,CONCAT(Timesheet!$P$5," ",Timesheet!$P$4,""),"")
AE5AE5=IF(Timesheet!Q15>0,CONCAT(Timesheet!$Q$5," ",Timesheet!$Q$4,""),"")
AF5AF5=IF(Timesheet!R15>0,CONCAT(Timesheet!$R$5," ",Timesheet!$R$4,""),"")
AG5AG5=IF(Timesheet!S15>0,CONCAT(Timesheet!$S$5," ",Timesheet!$S$4,""),"")
AH5AH5=IF(Timesheet!T15>0,CONCAT(Timesheet!$T$5," ",Timesheet!$T$4,""),"")
AI5AI5=IF(Timesheet!U15>0,CONCAT(Timesheet!$U$5," ",Timesheet!$U$4,""),"")
AJ5AJ5=IF(Timesheet!V15>0,CONCAT(Timesheet!$V$5," ",Timesheet!$V$4,""),"")
AK5AK5=IF(Timesheet!W15>0,CONCAT(Timesheet!$W$5," ",Timesheet!$W$4,""),"")
AL5AL5=IF(Timesheet!X15>0,CONCAT(Timesheet!$X$5," ",Timesheet!$X$4,""),"")
AM5AM5=IF(Timesheet!Y15>0,CONCAT(Timesheet!$Y$5," ",Timesheet!$Y$4,""),"")
AN5AN5=IF(Timesheet!Z15>0,CONCAT(Timesheet!$Z$5," ",Timesheet!$Z$4,""),"")
AO5AO5=IF(Timesheet!AA15>0,CONCAT(Timesheet!$AA$5," ",Timesheet!$AA$4,""),"")
AP5AP5=IF(Timesheet!AB15>0,CONCAT(Timesheet!$AB$5," ",Timesheet!$AB$4,""),"")
AQ5AQ5=IF(Timesheet!AC15>0,CONCAT(Timesheet!$AC$5," ",Timesheet!$AC$4,""),"")
AR5AR5=IF(Timesheet!AD15>0,CONCAT(Timesheet!$AD$5," ",Timesheet!$AD$4,""),"")
AS5AS5=IF(Timesheet!AE15>0,CONCAT(Timesheet!$AE$5," ",Timesheet!$AE$4,""),"")
AT5AT5=IF(Timesheet!AF15>0,CONCAT(Timesheet!$AF$5," ",Timesheet!$AF$4,""),"")
AU5AU5=IF(Timesheet!AG15>0,CONCAT(Timesheet!$AG$5," ",Timesheet!$AG$4,""),"")
A8A8=IF(Timesheet!AI16=0,"",Timesheet!$C$15)
B8B8=IF($A$8<>"","RH","")
V8V8=IF(Timesheet!H16>0,CONCAT(Timesheet!$H$5," ",Timesheet!$H$4,""),"")
W8W8=IF(Timesheet!I16>0,CONCAT(Timesheet!$I$5," ",Timesheet!$I$4,""),"")
X8X8=IF(Timesheet!J16>0,CONCAT(Timesheet!$J$5," ",Timesheet!$J$4,""),"")
Y8Y8=IF(Timesheet!K16>0,CONCAT(Timesheet!$K$5," ",Timesheet!$K$4,""),"")
Z8Z8=IF(Timesheet!L16>0,CONCAT(Timesheet!$L$5," ",Timesheet!$L$4,""),"")
AA8AA8=IF(Timesheet!M16>0,CONCAT(Timesheet!$M$5," ",Timesheet!$M$4,""),"")
AB8AB8=IF(Timesheet!N16>0,CONCAT(Timesheet!$N$5," ",Timesheet!$N$4,""),"")
AC8AC8=IF(Timesheet!O16>0,CONCAT(Timesheet!$O$5," ",Timesheet!$O$4,""),"")
AD8AD8=IF(Timesheet!P16>0,CONCAT(Timesheet!$P$5," ",Timesheet!$P$4,""),"")
AE8AE8=IF(Timesheet!Q16>0,CONCAT(Timesheet!$Q$5," ",Timesheet!$Q$4,""),"")
AF8AF8=IF(Timesheet!R16>0,CONCAT(Timesheet!$R$5," ",Timesheet!$R$4,""),"")
AG8AG8=IF(Timesheet!S16>0,CONCAT(Timesheet!$S$5," ",Timesheet!$S$4,""),"")
AH8AH8=IF(Timesheet!T16>0,CONCAT(Timesheet!$T$5," ",Timesheet!$T$4,""),"")
AI8AI8=IF(Timesheet!U16>0,CONCAT(Timesheet!$U$5," ",Timesheet!$U$4,""),"")
AJ8AJ8=IF(Timesheet!V16>0,CONCAT(Timesheet!$V$5," ",Timesheet!$V$4,""),"")
AK8AK8=IF(Timesheet!W16>0,CONCAT(Timesheet!$W$5," ",Timesheet!$W$4,""),"")
AL8AL8=IF(Timesheet!X16>0,CONCAT(Timesheet!$X$5," ",Timesheet!$X$4,""),"")
AM8AM8=IF(Timesheet!Y16>0,CONCAT(Timesheet!$Y$5," ",Timesheet!$Y$4,""),"")
AN8AN8=IF(Timesheet!Z16>0,CONCAT(Timesheet!$Z$5," ",Timesheet!$Z$4,""),"")
AO8AO8=IF(Timesheet!AA16>0,CONCAT(Timesheet!$AA$5," ",Timesheet!$AA$4,""),"")
AP8AP8=IF(Timesheet!AB16>0,CONCAT(Timesheet!$AB$5," ",Timesheet!$AB$4,""),"")
AQ8AQ8=IF(Timesheet!AC16>0,CONCAT(Timesheet!$AC$5," ",Timesheet!$AC$4,""),"")
AR8AR8=IF(Timesheet!AD16>0,CONCAT(Timesheet!$AD$5," ",Timesheet!$AD$4,""),"")
AS8AS8=IF(Timesheet!AE16>0,CONCAT(Timesheet!$AE$5," ",Timesheet!$AE$4,""),"")
AT8AT8=IF(Timesheet!AF16>0,CONCAT(Timesheet!$AF$5," ",Timesheet!$AF$4,""),"")
AU8AU8=IF(Timesheet!AG16>0,CONCAT(Timesheet!$AG$5," ",Timesheet!$AG$4,""),"")
A11A11=IF(Timesheet!AI17=0,"",Timesheet!$C$15)
B11B11=IF($A$11<>"","DT","")
V11V11=IF(Timesheet!H17>0,CONCAT(Timesheet!$H$5," ",Timesheet!$H$4,""),"")
W11W11=IF(Timesheet!I17>0,CONCAT(Timesheet!$I$5," ",Timesheet!$I$4,""),"")
X11X11=IF(Timesheet!J17>0,CONCAT(Timesheet!$J$5," ",Timesheet!$J$4,""),"")
Y11Y11=IF(Timesheet!K17>0,CONCAT(Timesheet!$K$5," ",Timesheet!$K$4,""),"")
Z11Z11=IF(Timesheet!L17>0,CONCAT(Timesheet!$L$5," ",Timesheet!$L$4,""),"")
AA11AA11=IF(Timesheet!M17>0,CONCAT(Timesheet!$M$5," ",Timesheet!$M$4,""),"")
AB11AB11=IF(Timesheet!N17>0,CONCAT(Timesheet!$N$5," ",Timesheet!$N$4,""),"")
AC11AC11=IF(Timesheet!O17>0,CONCAT(Timesheet!$O$5," ",Timesheet!$O$4,""),"")
AD11AD11=IF(Timesheet!P17>0,CONCAT(Timesheet!$P$5," ",Timesheet!$P$4,""),"")
AE11AE11=IF(Timesheet!Q17>0,CONCAT(Timesheet!$Q$5," ",Timesheet!$Q$4,""),"")
AF11AF11=IF(Timesheet!R17>0,CONCAT(Timesheet!$R$5," ",Timesheet!$R$4,""),"")
AG11AG11=IF(Timesheet!S17>0,CONCAT(Timesheet!$S$5," ",Timesheet!$S$4,""),"")
AH11AH11=IF(Timesheet!T17>0,CONCAT(Timesheet!$T$5," ",Timesheet!$T$4,""),"")
AI11AI11=IF(Timesheet!U17>0,CONCAT(Timesheet!$U$5," ",Timesheet!$U$4,""),"")
AJ11AJ11=IF(Timesheet!V17>0,CONCAT(Timesheet!$V$5," ",Timesheet!$V$4,""),"")
AK11AK11=IF(Timesheet!W17>0,CONCAT(Timesheet!$W$5," ",Timesheet!$W$4,""),"")
AL11AL11=IF(Timesheet!X17>0,CONCAT(Timesheet!$X$5," ",Timesheet!$X$4,""),"")
AM11AM11=IF(Timesheet!Y17>0,CONCAT(Timesheet!$Y$5," ",Timesheet!$Y$4,""),"")
AN11AN11=IF(Timesheet!Z17>0,CONCAT(Timesheet!$Z$5," ",Timesheet!$Z$4,""),"")
AO11AO11=IF(Timesheet!AA17>0,CONCAT(Timesheet!$AA$5," ",Timesheet!$AA$4,""),"")
AP11AP11=IF(Timesheet!AB17>0,CONCAT(Timesheet!$AB$5," ",Timesheet!$AB$4,""),"")
AQ11AQ11=IF(Timesheet!AC17>0,CONCAT(Timesheet!$AC$5," ",Timesheet!$AC$4,""),"")
AR11AR11=IF(Timesheet!AD17>0,CONCAT(Timesheet!$AD$5," ",Timesheet!$AD$4,""),"")
AS11AS11=IF(Timesheet!AE17>0,CONCAT(Timesheet!$AE$5," ",Timesheet!$AE$4,""),"")
AT11AT11=IF(Timesheet!AF17>0,CONCAT(Timesheet!$AF$5," ",Timesheet!$AF$4,""),"")
AU11AU11=IF(Timesheet!AG17>0,CONCAT(Timesheet!$AG$5," ",Timesheet!$AG$4,""),"")
A15A15=IF(Timesheet!AI19=0,"",Timesheet!F19)
V15V15=IF(Timesheet!H19>0,CONCAT(Timesheet!$H$5," ",Timesheet!$H$4,""),"")
W15W15=IF(Timesheet!I19>0,CONCAT(Timesheet!$I$5," ",Timesheet!$I$4,""),"")
X15X15=IF(Timesheet!J19>0,CONCAT(Timesheet!$J$5," ",Timesheet!$J$4,""),"")
Y15Y15=IF(Timesheet!K19>0,CONCAT(Timesheet!$K$5," ",Timesheet!$K$4,""),"")
Z15Z15=IF(Timesheet!L19>0,CONCAT(Timesheet!$L$5," ",Timesheet!$L$4,""),"")
AA15AA15=IF(Timesheet!M19>0,CONCAT(Timesheet!$M$5," ",Timesheet!$M$4,""),"")
AB15AB15=IF(Timesheet!N19>0,CONCAT(Timesheet!$N$5," ",Timesheet!$N$4,""),"")
AC15AC15=IF(Timesheet!O19>0,CONCAT(Timesheet!$O$5," ",Timesheet!$O$4,""),"")
AD15AD15=IF(Timesheet!P19>0,CONCAT(Timesheet!$P$5," ",Timesheet!$P$4,""),"")
AE15AE15=IF(Timesheet!Q19>0,CONCAT(Timesheet!$Q$5," ",Timesheet!$Q$4,""),"")
AF15AF15=IF(Timesheet!R19>0,CONCAT(Timesheet!$R$5," ",Timesheet!$R$4,""),"")
AG15AG15=IF(Timesheet!S19>0,CONCAT(Timesheet!$S$5," ",Timesheet!$S$4,""),"")
AH15AH15=IF(Timesheet!T19>0,CONCAT(Timesheet!$T$5," ",Timesheet!$T$4,""),"")
AI15AI15=IF(Timesheet!U19>0,CONCAT(Timesheet!$U$5," ",Timesheet!$U$4,""),"")
AJ15AJ15=IF(Timesheet!V19>0,CONCAT(Timesheet!$V$5," ",Timesheet!$V$4,""),"")
AK15AK15=IF(Timesheet!W19>0,CONCAT(Timesheet!$W$5," ",Timesheet!$W$4,""),"")
AL15AL15=IF(Timesheet!X19>0,CONCAT(Timesheet!$X$5," ",Timesheet!$X$4,""),"")
AM15AM15=IF(Timesheet!Y19>0,CONCAT(Timesheet!$Y$5," ",Timesheet!$Y$4,""),"")
AN15AN15=IF(Timesheet!Z19>0,CONCAT(Timesheet!$Z$5," ",Timesheet!$Z$4,""),"")
AO15AO15=IF(Timesheet!AA19>0,CONCAT(Timesheet!$AA$5," ",Timesheet!$AA$4,""),"")
AP15AP15=IF(Timesheet!AB19>0,CONCAT(Timesheet!$AB$5," ",Timesheet!$AB$4,""),"")
AQ15AQ15=IF(Timesheet!AC19>0,CONCAT(Timesheet!$AC$5," ",Timesheet!$AC$4,""),"")
AR15AR15=IF(Timesheet!AD19>0,CONCAT(Timesheet!$AD$5," ",Timesheet!$AD$4,""),"")
AS15AS15=IF(Timesheet!AE19>0,CONCAT(Timesheet!$AE$5," ",Timesheet!$AE$4,""),"")
AT15AT15=IF(Timesheet!AF19>0,CONCAT(Timesheet!$AF$5," ",Timesheet!$AF$4,""),"")
AU15AU15=IF(Timesheet!AG19>0,CONCAT(Timesheet!$AG$5," ",Timesheet!$AG$4,""),"")
A17A17=IF(Timesheet!AI20=0,"",Timesheet!F20)
B17B17=IF($A$17<>"","RH","")
V17V17=IF(Timesheet!H20>0,CONCAT(Timesheet!$H$5," ",Timesheet!$H$4,""),"")
W17W17=IF(Timesheet!I20>0,CONCAT(Timesheet!$I$5," ",Timesheet!$I$4,""),"")
X17X17=IF(Timesheet!J20>0,CONCAT(Timesheet!$J$5," ",Timesheet!$J$4,""),"")
Y17Y17=IF(Timesheet!K20>0,CONCAT(Timesheet!$K$5," ",Timesheet!$K$4,""),"")
Z17Z17=IF(Timesheet!L20>0,CONCAT(Timesheet!$L$5," ",Timesheet!$L$4,""),"")
AA17AA17=IF(Timesheet!M20>0,CONCAT(Timesheet!$M$5," ",Timesheet!$M$4,""),"")
AB17AB17=IF(Timesheet!N20>0,CONCAT(Timesheet!$N$5," ",Timesheet!$N$4,""),"")
AC17AC17=IF(Timesheet!O20>0,CONCAT(Timesheet!$O$5," ",Timesheet!$O$4,""),"")
AD17AD17=IF(Timesheet!P20>0,CONCAT(Timesheet!$P$5," ",Timesheet!$P$4,""),"")
AE17AE17=IF(Timesheet!Q20>0,CONCAT(Timesheet!$Q$5," ",Timesheet!$Q$4,""),"")
AF17AF17=IF(Timesheet!R20>0,CONCAT(Timesheet!$R$5," ",Timesheet!$R$4,""),"")
AG17AG17=IF(Timesheet!S20>0,CONCAT(Timesheet!$S$5," ",Timesheet!$S$4,""),"")
AH17AH17=IF(Timesheet!T20>0,CONCAT(Timesheet!$T$5," ",Timesheet!$T$4,""),"")
AI17AI17=IF(Timesheet!U20>0,CONCAT(Timesheet!$U$5," ",Timesheet!$U$4,""),"")
AJ17AJ17=IF(Timesheet!V20>0,CONCAT(Timesheet!$V$5," ",Timesheet!$V$4,""),"")
AK17AK17=IF(Timesheet!W20>0,CONCAT(Timesheet!$W$5," ",Timesheet!$W$4,""),"")
AL17AL17=IF(Timesheet!X20>0,CONCAT(Timesheet!$X$5," ",Timesheet!$X$4,""),"")
AM17AM17=IF(Timesheet!Y20>0,CONCAT(Timesheet!$Y$5," ",Timesheet!$Y$4,""),"")
AN17AN17=IF(Timesheet!Z20>0,CONCAT(Timesheet!$Z$5," ",Timesheet!$Z$4,""),"")
AO17AO17=IF(Timesheet!AA20>0,CONCAT(Timesheet!$AA$5," ",Timesheet!$AA$4,""),"")
AP17AP17=IF(Timesheet!AB20>0,CONCAT(Timesheet!$AB$5," ",Timesheet!$AB$4,""),"")
AQ17AQ17=IF(Timesheet!AC20>0,CONCAT(Timesheet!$AC$5," ",Timesheet!$AC$4,""),"")
AR17AR17=IF(Timesheet!AD20>0,CONCAT(Timesheet!$AD$5," ",Timesheet!$AD$4,""),"")
AS17AS17=IF(Timesheet!AE20>0,CONCAT(Timesheet!$AE$5," ",Timesheet!$AE$4,""),"")
AT17AT17=IF(Timesheet!AF20>0,CONCAT(Timesheet!$AF$5," ",Timesheet!$AF$4,""),"")
AU17AU17=IF(Timesheet!AG20>0,CONCAT(Timesheet!$AG$5," ",Timesheet!$AG$4,""),"")
A19A19=IF(Timesheet!AI21=0,"",Timesheet!F21)
B19B19=IF(A19<>"","DT","")
V19V19=IF(Timesheet!H21>0,CONCAT(Timesheet!$H$5," ",Timesheet!$H$4,""),"")
W19W19=IF(Timesheet!I21>0,CONCAT(Timesheet!$I$5," ",Timesheet!$I$4,""),"")
X19X19=IF(Timesheet!J21>0,CONCAT(Timesheet!$J$5," ",Timesheet!$J$4,""),"")
Y19Y19=IF(Timesheet!K21>0,CONCAT(Timesheet!$K$5," ",Timesheet!$K$4,""),"")
Z19Z19=IF(Timesheet!L21>0,CONCAT(Timesheet!$L$5," ",Timesheet!$L$4,""),"")
AA19AA19=IF(Timesheet!M21>0,CONCAT(Timesheet!$M$5," ",Timesheet!$M$4,""),"")
AB19AB19=IF(Timesheet!N21>0,CONCAT(Timesheet!$N$5," ",Timesheet!$N$4,""),"")
AC19AC19=IF(Timesheet!O21>0,CONCAT(Timesheet!$O$5," ",Timesheet!$O$4,""),"")
AD19AD19=IF(Timesheet!P21>0,CONCAT(Timesheet!$P$5," ",Timesheet!$P$4,""),"")
AE19AE19=IF(Timesheet!Q21>0,CONCAT(Timesheet!$Q$5," ",Timesheet!$Q$4,""),"")
AF19AF19=IF(Timesheet!R21>0,CONCAT(Timesheet!$R$5," ",Timesheet!$R$4,""),"")
AG19AG19=IF(Timesheet!S21>0,CONCAT(Timesheet!$S$5," ",Timesheet!$S$4,""),"")
AH19AH19=IF(Timesheet!T21>0,CONCAT(Timesheet!$T$5," ",Timesheet!$T$4,""),"")
AI19AI19=IF(Timesheet!U21>0,CONCAT(Timesheet!$U$5," ",Timesheet!$U$4,""),"")
AJ19AJ19=IF(Timesheet!V21>0,CONCAT(Timesheet!$V$5," ",Timesheet!$V$4,""),"")
AK19AK19=IF(Timesheet!W21>0,CONCAT(Timesheet!$W$5," ",Timesheet!$W$4,""),"")
AL19AL19=IF(Timesheet!X21>0,CONCAT(Timesheet!$X$5," ",Timesheet!$X$4,""),"")
AM19AM19=IF(Timesheet!Y21>0,CONCAT(Timesheet!$Y$5," ",Timesheet!$Y$4,""),"")
AN19AN19=IF(Timesheet!Z21>0,CONCAT(Timesheet!$Z$5," ",Timesheet!$Z$4,""),"")
AO19AO19=IF(Timesheet!AA21>0,CONCAT(Timesheet!$AA$5," ",Timesheet!$AA$4,""),"")
AP19AP19=IF(Timesheet!AB21>0,CONCAT(Timesheet!$AB$5," ",Timesheet!$AB$4,""),"")
AQ19AQ19=IF(Timesheet!AC21>0,CONCAT(Timesheet!$AC$5," ",Timesheet!$AC$4,""),"")
AR19AR19=IF(Timesheet!AD21>0,CONCAT(Timesheet!$AD$5," ",Timesheet!$AD$4,""),"")
AS19AS19=IF(Timesheet!AE21>0,CONCAT(Timesheet!$AE$5," ",Timesheet!$AE$4,""),"")
AT19AT19=IF(Timesheet!AF21>0,CONCAT(Timesheet!$AF$5," ",Timesheet!$AF$4,""),"")
AU19AU19=IF(Timesheet!AG21>0,CONCAT(Timesheet!$AG$5," ",Timesheet!$AG$4,""),"")
A21A21=IF(Timesheet!AI22=0,"",Timesheet!F22)
B21B21=IF($A$21<>"","IW","")
V21V21=IF(Timesheet!H22>0,CONCAT(Timesheet!$H$5," ",Timesheet!$H$4,""),"")
W21W21=IF(Timesheet!I22>0,CONCAT(Timesheet!$I$5," ",Timesheet!$I$4,""),"")
X21X21=IF(Timesheet!J22>0,CONCAT(Timesheet!$J$5," ",Timesheet!$J$4,""),"")
Y21Y21=IF(Timesheet!K22>0,CONCAT(Timesheet!$K$5," ",Timesheet!$K$4,""),"")
Z21Z21=IF(Timesheet!L22>0,CONCAT(Timesheet!$L$5," ",Timesheet!$L$4,""),"")
AA21AA21=IF(Timesheet!M22>0,CONCAT(Timesheet!$M$5," ",Timesheet!$M$4,""),"")
AB21AB21=IF(Timesheet!N22>0,CONCAT(Timesheet!$N$5," ",Timesheet!$N$4,""),"")
AC21AC21=IF(Timesheet!O22>0,CONCAT(Timesheet!$O$5," ",Timesheet!$O$4,""),"")
AD21AD21=IF(Timesheet!P22>0,CONCAT(Timesheet!$P$5," ",Timesheet!$P$4,""),"")
AE21AE21=IF(Timesheet!Q22>0,CONCAT(Timesheet!$Q$5," ",Timesheet!$Q$4,""),"")
AF21AF21=IF(Timesheet!R22>0,CONCAT(Timesheet!$R$5," ",Timesheet!$R$4,""),"")
AG21AG21=IF(Timesheet!S22>0,CONCAT(Timesheet!$S$5," ",Timesheet!$S$4,""),"")
AH21AH21=IF(Timesheet!T22>0,CONCAT(Timesheet!$T$5," ",Timesheet!$T$4,""),"")
AI21AI21=IF(Timesheet!U22>0,CONCAT(Timesheet!$U$5," ",Timesheet!$U$4,""),"")
AJ21AJ21=IF(Timesheet!V22>0,CONCAT(Timesheet!$V$5," ",Timesheet!$V$4,""),"")
AK21AK21=IF(Timesheet!W22>0,CONCAT(Timesheet!$W$5," ",Timesheet!$W$4,""),"")
AL21AL21=IF(Timesheet!X22>0,CONCAT(Timesheet!$X$5," ",Timesheet!$X$4,""),"")
AM21AM21=IF(Timesheet!Y22>0,CONCAT(Timesheet!$Y$5," ",Timesheet!$Y$4,""),"")
AN21AN21=IF(Timesheet!Z22>0,CONCAT(Timesheet!$Z$5," ",Timesheet!$Z$4,""),"")
AO21AO21=IF(Timesheet!AA22>0,CONCAT(Timesheet!$AA$5," ",Timesheet!$AA$4,""),"")
AP21AP21=IF(Timesheet!AB22>0,CONCAT(Timesheet!$AB$5," ",Timesheet!$AB$4,""),"")
AQ21AQ21=IF(Timesheet!AC22>0,CONCAT(Timesheet!$AC$5," ",Timesheet!$AC$4,""),"")
AR21AR21=IF(Timesheet!AD22>0,CONCAT(Timesheet!$AD$5," ",Timesheet!$AD$4,""),"")
AS21AS21=IF(Timesheet!AE22>0,CONCAT(Timesheet!$AE$5," ",Timesheet!$AE$4,""),"")
AT21AT21=IF(Timesheet!AF22>0,CONCAT(Timesheet!$AF$5," ",Timesheet!$AF$4,""),"")
AU21AU21=IF(Timesheet!AG22>0,CONCAT(Timesheet!$AG$5," ",Timesheet!$AG$4,""),"")
 
Upvote 0
The detail is that in column A you have formulas and the macro looks for values.
Try the following:

VBA Code:
Sub AddUniqueValues()
  Dim a As Range, dic As Object, j As Long
  For Each a In Range("A2", Range("A" & Rows.Count).End(3)).SpecialCells(xlCellTypeFormulas, 23)
    Set dic = CreateObject("Scripting.Dictionary")
    For j = 4 To Cells(a.Row, Columns.Count).End(1).Column
      If Cells(a.Row, j) <> "" Then dic(Cells(a.Row, j).Value) = Empty
    Next
    a.Offset(dic.Count * -1, 3).Resize(dic.Count).Value = Application.Transpose(dic.keys)
  Next
End Sub
 
Upvote 0
@DanteAmor Column D autofills with the correct values which is wonderful, but I am getting a run-time error '13': Type mismatch regarding the highlighted text in VBA. I have attached an image. If there is a way to fix this, that would be great, but if not, that is fine, too. Thank you.
 

Attachments

  • Run-time 13.PNG
    Run-time 13.PNG
    90.7 KB · Views: 4
Upvote 0
Check your data, this error is because in a cell in column A, let's say cell A56, you have data but in the columns of E to the right of row 56 they are empty, that is, there is nothing to add. To avoid the error, try the following:

VBA Code:
Sub AddUniqueValues()
  Dim a As Range, dic As Object, j As Long
  For Each a In Range("A2", Range("A" & Rows.Count).End(3)).SpecialCells(xlCellTypeFormulas, 23)
    Set dic = CreateObject("Scripting.Dictionary")
    For j = 5 To Cells(a.Row, Columns.Count).End(1).Column
      If Cells(a.Row, j) <> "" Then dic(Cells(a.Row, j).Value) = Empty
    Next
    On Error Resume Next
    a.Offset(dic.Count * -1, 3).Resize(dic.Count).Value = Application.Transpose(dic.keys)
    On Error GoTo 0
  Next
End Sub
 
Upvote 0
Solution
Check your data, this error is because in a cell in column A, let's say cell A56, you have data but in the columns of E to the right of row 56 they are empty, that is, there is nothing to add. To avoid the error, try the following:

VBA Code:
Sub AddUniqueValues()
  Dim a As Range, dic As Object, j As Long
  For Each a In Range("A2", Range("A" & Rows.Count).End(3)).SpecialCells(xlCellTypeFormulas, 23)
    Set dic = CreateObject("Scripting.Dictionary")
    For j = 5 To Cells(a.Row, Columns.Count).End(1).Column
      If Cells(a.Row, j) <> "" Then dic(Cells(a.Row, j).Value) = Empty
    Next
    On Error Resume Next
    a.Offset(dic.Count * -1, 3).Resize(dic.Count).Value = Application.Transpose(dic.keys)
    On Error GoTo 0
  Next
End Sub
Incredible! Thank you so much for all your help! This answered my original post and worked flawlessly. Again, thank you!
 
Upvote 0

Forum statistics

Threads
1,214,810
Messages
6,121,690
Members
449,048
Latest member
81jamesacct

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