复制工作表会搞乱数据验证

时间:2019-06-06 18:45:45

标签: excel vba

当我尝试将数据从一个工作簿导入到另一个具有相同数据需求的工作簿时,旧工作簿将使用相同的引用。它弄乱了我复制的工作簿中的数据验证,使之成为'OldWorkbookSpecificSheet'!$ p $ 2:$ p $ 3。有什么我可以解决的方法吗?还是我每次想更改某些内容时都必须再次创建数据验证。任何帮助将不胜感激。

Sub CopyWorkbook(WB As String)

    Dim i As Integer
    Dim OtherWBVersion As String

    If (OtherWBVersion > "0510") Then
      With ThisWorkbook
         For i = 0 To 19
           .ImportRange WB, Me.Name, "F" & (4 + i * 25) & ":F" & (15 + i * 25)
           .ImportRange WB, Me.Name, "G" & (4 + i * 25) & ":S" & (15 + i * 25)
           .ImportRange WB, Me.Name, "E" & (18 + i * 25) & ":G" & (24 + i * 25)
           .ImportRange WB, Me.Name, "H" & (18 + i * 25) & ":H" & (24 + i * 25)
           .ImportRange WB, Me.Name, "J" & (18 + i * 25) & ":K" & (24 + i * 25)
           .ImportRange WB, Me.Name, "L" & (18 + i * 25) & ":L" & (24 + i * 25)

           .ImportRange WB, Me.Name, "N" & (20 + i * 25)
           .ImportRange WB, Me.Name, "Q" & (20 + i * 25)
           .ImportRange WB, Me.Name, "Q" & (22 + i * 25)
           .ImportRange WB, Me.Name, "P" & (22 + i * 25)
            .ImportRange WB, Me.Name, "N" & (22 + i * 25)
         Next i
      End With
     End If
End Sub






    Sub ImportRange(WB As String, WS As String, RngTo As String, Optional   RngFrom As String)
    If RngFrom = "" Then
        RngFrom = RngTo
    End If

    ActiveWorkbook.Worksheets(WS).Range(RngTo).Value = Workbooks(WB).Worksheets(WS).Range(RngFrom).Value
    End Sub

0 个答案:

没有答案