Input box range - output range

  • Thread starter Thread starter al007
  • Start date Start date
A

al007

Sub UniqueFindColumn()
Dim AnArray() As String, i As Long
Dim Selec As Range
Dim Desti As Range
Set Selec = Application.InputBox( _
Prompt:="Select cell for Actual data.", Type:=8)

Set Desti = Application.InputBox( _
Prompt:="Select cell for Actual data.", Type:=8)
AnArray = GetUniqueEntries(Selec)
If Len(AnArray(0)) > 0 Then
For i = 0 To UBound(AnArray)
Range(Desti).Offset(i, 0) = AnArray(i)
Next
End If
End Sub

What wrong in the above macro with respect to my output i.e Desti
range.
Thxs

Actual I tried to amend the macro below:
Sub UniqueFind()
Dim AnArray() As String, i As Long
AnArray = GetUniqueEntries(Range("A1:D12"))
If Len(AnArray(0)) > 0 Then
For i = 0 To UBound(AnArray)
Range("F1").Offset(i, 0) = AnArray(i)
Next
End If
End Sub
 
Hello al007,

The range object variables must be set to an existing reference. I made
the changes to your code for you. The InputBox is merely supplying a
string address that describes the range and is not itself a range. You
can not reference cells that are not on the active sheet with this
Sub.

Sub UniqueFindColumn()
Dim AnArray() As String, i As Long
Dim Selec As Range
Dim Desti As Range
Dim Rng
Rng = Application.InputBox( _
Prompt:="Select cell for Actual data.", Type:=8)
Set Selec = Range(Rng)

Rng = Application.InputBox( _
Prompt:="Select cell for Actual data.", Type:=8)
Set Desti = Range(Rng)
AnArray = GetUniqueEntries(Selec)
If Len(AnArray(0)) > 0 Then
For i = 0 To UBound(AnArray)
Range(Desti).Offset(i, 0) = AnArray(i)
Next
End If
End Sub
 
Desti is already a range.

I think you want:
Desti.Offset(i, 0) = AnArray(i)

instead of:
Range(Desti).Offset(i, 0) = AnArray(i)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top