从外部工作簿中提取信息,而不更改以前创建的当前Excel边框和格式

时间:2015-08-19 02:01:51

标签: excel vba excel-vba

您好我能够运行一个代码来帮助我从2个工作簿运行每个ID,一旦匹配,来自工作簿A的信息被称为活动主文件将被复制到工作簿B,称为新加坡仪表板文件。但是我遇到的一个问题是,当复制值并将其放入工作簿B时,格式不同,并且在复制到工作簿B时也从表中删除了边框。是否需要插入任何其他代码为了在复制值时,工作簿B的格式保持不变。 这是我的代码:

    Sub UpdatePar()
    Dim dashboard As Worksheet
    Dim master As Worksheet
    Dim cell As Range
    Dim cellFound As Range

   Set dashboard = Workbooks("Singapore Project Dashboard -Jul 2015.xlsm").Sheets("Projects Details")
   Set master = Workbooks("Active_Project_List_–_Master_Project(s).xlsm").Sheets("Active Master Project List")


    For Each cell In master.Range("G6:G800")
        ' Try to find this value in the source sheet
        Set cellFound = dashboard.Range("G:G").Find(What:=cell.Value, LookIn:=xlValues, LookAt:=xlWhole)
        If Not cellFound Is Nothing Then
            ' A matching value was found
            ' So copy the cell 2 columns across to the cell adjacent to matching value
            ' Do a "normal" copy & paste
            cell.Offset(ColumnOffset:=66).Copy cellFound.Offset(ColumnOffset:=1)
            ' Or do a copy & paste special values
            'cell.Offset(ColumnOffset:=2).Copy
            'cellFound.Offset(ColumnOffset:=1).PasteSpecial xlPasteValues

        Else
            ' The value in this cell does not exist in the source
            ' Should anything be done?
        End If
    Next

End Sub

我希望有人能帮助我。谢谢:))

0 个答案:

没有答案