将粘贴范围(使用设置值)复制到不同的工作簿

我有两个工作簿, wbwb2 。 我想做的事,

  1. 复制数据从工作表wb到工作表Nov Temp wb这部分,代码正在工作。

  2. wb特定范围复制到wb2 。 //我尝试使用Rng来设置值,但是由于我处理范围的方式,这可能不起作用。 Rng in (myRange = sht.Rng.Value)被突出显示

    编译错误; 方法或数据成员未find。

请帮忙…

 Option Explicit Sub cont() Application.Volatile Dim sht As Worksheet Dim myRange As Variant Dim Rng As Range Dim Lastrow, ecol, eRow As Integer Dim station As String Dim wb As Workbook, wb2 As Workbook Set wb = ActiveWorkbook wb.Sheets("Nov").Activate eRow = Cells(Rows.Count, 2).End(xlUp).Row station = Range("B2").Value Range(Cells(2, 2), Cells(eRow, 2)).Copy MsgBox "Transfer data for station: " & station On Error GoTo 0 wb.Sheets("Nov Template").Activate Set sht = ActiveWorkbook.Sheets("Nov Template") ecol = sht.UsedRange.Columns.Count sht.Range(Cells(1, 2), Cells(eRow, 2)).PasteSpecial xlPasteValues With ActiveSheet.UsedRange Lastrow = .Rows(.Rows.Count).Row Set Rng = Range(Cells(1, "C"), Cells(Lastrow, ecol)) myRange = sht.Rng.Value End With Workbooks.Open "G:\Mean2std\Merge NDj (2).xlsm" Set wb2 = ActiveWorkbook wb2.Worksheets("GM").Range("B3:AO32").Value = myRange wb2.Close SaveChanges:=True End Sub 

现在它工作,删除myRange,并单独使用Rng。

 Option Explicit Sub cont() Application.Volatile Dim sht As Worksheet 'Dim myRange As Variant Dim Rng As Range Dim Lastrow, ecol, eRow As Long Dim station As String Dim wb As Workbook, wb2 As Workbook Set wb = ActiveWorkbook wb.Sheets("Nov").Activate eRow = Cells(Rows.Count, 2).End(xlUp).Row station = Range("B2").Value Range(Cells(2, 2), Cells(eRow, 2)).Copy MsgBox "Transfer data for station: " & station wb.Sheets("Nov Template").Activate Set sht = ActiveWorkbook.Sheets("Nov Template") ecol = sht.UsedRange.Columns.Count sht.Range(Cells(1, 2), Cells(eRow, 2)).PasteSpecial xlPasteValues With ActiveSheet.UsedRange Lastrow = .Rows(.Rows.Count).Row Set Rng = Range(Cells(1, "C"), Cells(Lastrow, ecol)) 'myRange = sht.Rng.Value End With Workbooks.Open "G:\Mean2std\Merge NDj (2).xlsm" Set wb2 = ActiveWorkbook 'wb2.Worksheets("GM").Range("B3:AO32").Value = myRange wb2.Worksheets("GM").Range("B3:AO32").Value = Rng.Value wb2.Close SaveChanges:=True End Sub