0

So today I tried to select a row from an Excel file then paste it in another row (in another Excel file)

I've searched the web and Stack Overflow and nothing helped me. I don't know anything about VB and I don't have time because I need this by Saturday and almost everything is vague for me but this is my code:

Sub main()

Dim rangeSrc As range, range As range

Set rangeSrc = Application.InputBox("Select src Range", "select src range")
Set range = Application.InputBox("select des range", "select des range")
rangeSrc.Select
Selection.Copy

range.Select
ActiveSheet.Paste

End Sub 

There is what I have gathered form all around the web .

The first problem is that it keeps giving me OBJECT REQUIRED error.

The second problem is that if (in the future) I want to add a condition to selecting rows, what should I do?

Thanks

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Khesht
  • 5
  • 1

1 Answers1

0

Try this. I'd use range1 or something other than range for a variable name. Also read how to avoid select. You'll probably have to check the size of the ranges, range1 should be a single cell or the same size as rangesrc.

Sub main()

Dim rangeSrc As range, range1 As range

Set rangeSrc = Application.InputBox("Select src Range", "select src range", Type:=8) 'type 8 = range
Set range1 = Application.InputBox("select des range", "select des range", Type:=8)

If Not rangeSrc Is Nothing And Not range1 Is Nothing Then
    rangeSrc.Copy range1
End If

End Sub
SJR
  • 22,986
  • 6
  • 18
  • 26