复制和粘贴不会复制excel vba中的单元格边框

guykilcj  于 2023-01-21  发布在  其他
关注(0)|答案(1)|浏览(228)

我无法复制整个单元格(包括所有边框)并将其粘贴到相邻单元格。原始工作表显示在1.jpg中。我想删除第18行中的P1。完成后,U2将连同其边框格式一起删除到G列。但我在G列中看到蓝色的下边框,如2.jpg所示。预期结果显示在3.jpg中

For col_num = col_num To 12
                                        
    'MsgBox stored_row & col_num
                                        
                                       
         If col_num = 12 Then
            Exit For
         End If
        
            If Sheets("DSS").Cells(stored_row, col_num + 1).Value <> "" Then
                
                Sheets("DSS").Cells(stored_row, col_num + 1).Copy
                Sheets("DSS").Cells(stored_row, col_num).PasteSpecial
                Application.CutCopyMode = False

                Sheets("DSS").Cells(stored_row, col_num + 1).Value = ""
            
            ElseIf Sheets("DSS").Cells(stored_row, col_num + 1).Value = "" Then
                
                Sheets("DSS").Cells(stored_row, col_num + 1).Copy
                Sheets("DSS").Cells(stored_row, col_num).PasteSpecial
                Application.CutCopyMode = False

                'Exit For
            End If
            
            If Sheets("DSS").Cells(stored_row - 1, col_num).Value <> "" Then
                    Cells(stored_row, col_num).Select
                        With Selection.Borders(xlEdgeTop)
                            .LineStyle = xlContinuous
                            .Color = vbBlue
                            .TintAndShade = 0
                            .Weight = xlThick
                        End With
            End If
             If Sheets("DSS").Cells(stored_row + 1, col_num).Value <> "" Then
                    Cells(stored_row, col_num).Select
                        With Selection.Borders(xlEdgeBottom)
                            .LineStyle = xlContinuous
                            .Color = vbBlue
                            .TintAndShade = 0
                            .Weight = xlThick
                        End With
            End If
            
Next

我无法复制整个单元格(包括所有边框)并将其粘贴到相邻单元格上。
原始工作表显示在1.jpg中,我想从第18行删除P1。完成后,U2将连同其边框格式沿着移到G列。

但是我在G列中看到了蓝色的下边框,如2.jpg所示

预期结果如3.jpg所示

hzbexzde

hzbexzde1#

这可能会给予你一个方法来做你想要的:

Option Explicit

Sub Shift_Value_and_Borders_Left()
    Dim targetCell As Range, sourceCell As Range, x As Integer

    Set targetCell = Range("G18")
    Set sourceCell = targetCell.Offset(0, 1)
    
    targetCell.Value = sourceCell.Value
        
    For x = 5 To 12
        targetCell.Borders(x).LineStyle = sourceCell.Borders(x).LineStyle
        targetCell.Borders(x).Weight = sourceCell.Borders(x).Weight
        targetCell.Borders(x).Color = sourceCell.Borders(x).Color
    Next x

    Set sourceCell = Nothing
    Set targetCell = Nothing
End Sub

相关问题