Share via

How to code this macro?

Anonymous
2015-11-06T11:35:35+00:00

Referring to following code, I would like to set input Range(E5:F1000) and set output starting from Range(E5).

Does anyone have any suggestions on how to edit following input in macro?

Thanks in advance for any suggestions

SubFindUniques()

'Updateby20140313

Dim rng As Range

Dim InputRng As Range, OutRng As Range

xTitleId = "KutoolsforExcel"

Set InputRng = Application.Selection

Set InputRng = Application.InputBox("Range :", xTitleId, InputRng.Address, Type:=8)

Set OutRng = Application.InputBox("Out put to (single cell):", xTitleId, Type:=8)

Set dic = CreateObject("Scripting.Dictionary")

For j = 1 To InputRng.Columns.Count

    For i = 1 To InputRng.Rows.Count

        xValue = InputRng.Cells(i, j).Value

        If xValue <> "" And Not dic.Exists(xValue) Then

            OutRng.Value = xValue

            dic(xValue) = ""

            Set OutRng = OutRng.Offset(1, 0)

        End If

    Next

Next

End Sub

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2015-11-06T11:47:51+00:00

Hi,

Do you really want to set the output range starting in E5 because that would overwrite the original data? Here I set the output range to start in G5, you can change it to E5 if that's what you require.

Sub FindUniques()

 'Updateby20140313

 Dim rng As Range, j As Long, i As Long, xValue

 Dim InputRng As Range, OutRng As Range

 Dim dic

 Set InputRng = Range("E5:F1000")

 Set OutRng = Range("G5")

 Set dic = CreateObject("Scripting.Dictionary")

 For j = 1 To InputRng.Columns.count

     For i = 1 To InputRng.Rows.count

         xValue = InputRng.Cells(i, j).Value

         If xValue <> "" And Not dic.Exists(xValue) Then

             OutRng.Value = xValue

             dic(xValue) = ""

             Set OutRng = OutRng.Offset(1, 0)

         End If

     Next

 Next

 End Sub

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2015-11-06T12:18:32+00:00

    Thank you very much for suggestions :>

    Was this answer helpful?

    0 comments No comments