-1

基本上我将workbook1的单元格与workbook2链接起来,为整个电子表格执行此操作的代码是什么?我的错误没有得到清楚的解释,如下所示,我正在从 workbook2 分配 workbook1 中单元格的值

Sub Macro2() 
    Windows("workbook2.xlsx").Activate 
    Windows("workbook1.xlsx").Activate 
    ActiveCell.FormulaR1C1 = _ 
       "='[workbook2.xlsx]workbook1'!R18C1" 
    Range("A19").Select 
    ActiveCell.FormulaR1C1 = _
        "='[workbook2.xlsx]workbook1'!R19C1" 
    Range("A20").Select 
    ......... 
End Sub 

我想知道在 A9 到 A120、E9 到 E120、F9 到 F120 范围内最快的方法是什么.....

4

2 回答 2

1

此代码将链接所有工作表中的所有单元格:

Sub LinkSheets()
    Dim ws As Worksheet

    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False

    For Each ws In Worksheets
        ws.UsedRange.FormulaR1C1 = "='[workbook2.xlsx]" & ws.Name & "'!RC"
    Next

    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
End Sub

如果您只想链接一个工作表中的某些单元格,请尝试以下代码:

Sub LinkRange()
    Workbooks("workbook1.xlsx").Worksheets("Sheet1"). _
        Range("A9:A120,E9:E120,F9:F120").FormulaR1C1= _
        "='[workbook2.xlsx]Sheet1'!RC"
End Sub
于 2013-02-16T21:45:10.190 回答
0
Sub CopyPasteEntries()
 Dim i, g, h As Integer
 Sheets("Sheet1").Select
 Range("A1").EntireRow.Copy
 Sheets("Sheet2").Range("A1").PasteSpecial Paste:=xlPasteAll
 i = 2
 Sheets("Sheet1").Select
  Do Until IsEmpty(Cells(i, 1))  
  i = i + 1        
  Loop
  g = i - 1
  h = 2
  For i = 2 To g 
 Sheets("Sheet1").Select
  If Cells(i, 1).Value <> "Created" Then
   Cells(i, 1).EntireRow.Copy
 Sheets("Sheet2").Select
   Cells(h, 1).Select
 ActiveCell.PasteSpecial xlPasteAll
 h = h + 1
 End If     
  Next
 Application.CutCopyMode = False
 End Sub
于 2014-05-05T22:14:58.263 回答