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
  • 37,420
  • 30
  • 139
  • 188
Shan S
  • 49
  • 4
  • 8

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
  • 95,722
  • 10
  • 59
  • 99
  • 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