Error

ArbiterWolf

New Member
Joined
Jan 15, 2022
Messages
19
Office Version
  1. 2016
Platform
  1. Windows
Sub ExtractUniqueNames()
Dim ws As Worksheet
Dim rng As Range
Dim cell As Range
Dim dict As Object
Dim pasteRange As Range
Set ws = ThisWorkbook.Sheets("Data")
Set rng = ws.Range("E1:E" & ws.Range("E" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeConstants)
Set dict = CreateObject("Scripting.Dictionary")
Set pasteRange = ThisWorkbook.Sheets("SummaryPage").Range("B14:B31") 'set the range where you want to paste the unique names

For Each cell In rng
If cell.Value <> "N/A" And Not dict.Exists(cell.Value) And InStr(1, cell.Value, "inserts", vbTextCompare) = 0 Then
dict.Add cell.Value, cell.Value
End If
Next cell

pasteRange.Resize(dict.Count).Value = Application.Transpose(dict.Keys()) 'paste the unique names in the paste range
End Sub


I get a Run Time error Mismatch Type Error and it highlights the pasteRange.Resize(dict.Count).Value = Application.Transpose(dict.Keys()) line
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
That's because there is no matching data.
Replace this line:
pasteRange.Resize(dict.Count).Value = Application.Transpose(dict.Keys()) 'paste the unique names in the paste range

By these lines:

VBA Code:
  If dict.Count > 0 Then
    pasteRange.Resize(dict.Count).Value = Application.Transpose(dict.Keys) 'paste the unique names in the paste range
  Else
    MsgBox "No data"
  End If
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,591
Members
449,089
Latest member
Motoracer88

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