0

I don't know what is wrong with this code. it shows an error at Rng.select. When i tested on a separate sheet it worked. Any help?.

Sub copyex()
Dim Lastro As Integer
Dim oSht As Worksheet
Dim Rng As Range

'make exact copy at S6 for comparasion
 Set oSht = Workbooks("Main.xlsm").Sheets("Work")
 Lastro = oSht.Cells(Rows.Count, 2).End(xlUp).Row

With oSht
Set Rng = oSht.Range("B6:G" & Lastro)
      Rng.Select
      Selection.Copy
      Range("S6").Select
      ActiveSheet.Paste
End With
Jean-François Corbett
  • 36,032
  • 27
  • 135
  • 183
Shan S
  • 49
  • 4
  • 8
  • I've mentioned it before, but it bears repeating: [Please accept some answers](http://meta.stackoverflow.com/help/someone-answers). – Doug Glancy Oct 20 '13 at 18:42

1 Answers1

2

You must Select the Sheet before you Select the Range.

EDIT#1:

In your example, you probably do not have to Select the range....try replacing the two lines:

Rng.Select
Selection.Copy

with the single line:

Rng.Copy
Gary's Student
  • 94,018
  • 8
  • 54
  • 89
  • ya.. thats why i set my sheet to Workbooks("Main.xlsm").Sheets("Work"). isn't it right? – Shan S Oct 20 '13 at 17:05
  • You Set the range correctly, but you must Select or Activate the Sheet for you can Select or Activate the range...........I will update my Response. – Gary's Student Oct 20 '13 at 17:10