简体   繁体   English

VBA将值从一个工作簿复制到另一个工作簿

[英]VBA copy value from one workbook to another

I would like to copy a cell value from one workbook to another if the cell B54 is "No", but my code does not work. 如果单元格B54为“否”,我想将一个单元格值从一个工作簿复制到另一个工作簿,但是我的代码不起作用。

Option Explicit

Sub WorksheetLoop()
Dim WS_Count As Integer
Dim i As Integer

' Set WS_Count equal to the number of worksheets in the active workbook.
WS_Count = ActiveWorkbook.Worksheets.Count

' Begin the loop.
For i = 4 To WS_Count
   If Workbooks("Finding_Master Summary and Response Template.xlsm").Worksheets(i).Range(54, 2).Value = "No" Then
      Workbooks("finding Summary.xlsm").Sheets("Sheet1").Range(3, 1).Value = Workbooks("Finding_Master Summary and Response Template.xlsm").Sheets("Response Template").Range(54, 1).Value
   End If
Next i

End Sub

And this line does not work 而且这行不起作用

Workbooks("finding Summary.xlsm").Sheets("Sheet1").Range(3, 1).Value=Workbooks("Finding_Master Summary and Response Template.xlsm").Sheets("Response Template").Range(54, 1).Value

Try the following code: 尝试以下代码:

Option Explicit

Sub WorksheetLoop()

    Dim WS_Count As Integer
    Dim i As Integer

    ' Set WS_Count equal to the number of worksheets in the active workbook.
    WS_Count = ActiveWorkbook.Worksheets.count

   ' Begin the loop.
    For i = 4 To WS_Count
       If Workbooks("Finding_Master Summary and Response Template.xlsm").Worksheets(i).Cells(54, 2).Value = "No" Then
          Workbooks("finding Summary.xlsm").Worksheets("Sheet1").Cells(3, 1).Value = Workbooks("Finding_Master Summary and Response Template.xlsm").Worksheets("Response Template").Cells(54, 1).Value
       End If
    Next i

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM