如何将数据引用到不同的工作表(主工作表中具有不同的范围单元格)

时间:2018-05-16 07:23:55

标签: excel-vba vba excel

我正在构建一个Excel工作表,在其中使用相同excel的其他工作表中的引用单元复制数据我有:

Private Sub Worksheet_Change(ByVal Target As Range)

  If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub

    If Not Intersect(Target, Range("b10:B10")) Is Nothing Then

        If IsNumeric(Target) Then

            'Stop any possible runtime errors and halting code

            On Error Resume Next

                'Turn off ALL events so the Target does not put the code into a loop.

                Application.EnableEvents = False

                Call Update_Monthly

                'Turn events back on

                Application.EnableEvents = True

            'Allow run time errors again

            On Error GoTo 0

        End If

    End If



End Sub

我使用以下代码在WS2模块中创建了另一个代码:

Sub Update_Monthly()
Dim ws1 As Worksheet, ws2 As Worksheet
Set ws1 = Sheets("Daily Testing")
Set ws2 = Sheets("Monthly Record")
Application.ScreenUpdating = False
lr = ws2.Cells(Rows.Count, "C").End(xlUp).Row
For i = 1 To 5
ws2.Cells(i + lr, "C") = ws1.Cells(i + 5, "B")
Next i
Application.ScreenUpdating = True
End Sub

coloumn范围将数据引用到表2 现在,如果我有sheet3,表4 如何使用相同的代码w1引用数据(但仅在范围b10:B10中有差异?)

0 个答案:

没有答案