Copying and Pasting does not copy the cell borders

ajoy123rocks

New Member
Joined
Jul 13, 2022
Messages
9
Office Version
  1. 2019
Platform
  1. Windows
I am unable to copy the entire cell including all borders and paste it onto the adjacent cell.

The original sheet is shown in 1.jpg
I want to delete P1 from row 18. When this is done U2 will remove to column G along with its border formatting. But I see a blue bottom border in Column G as shown in 2.jpg
The expected result is shown in 3.jpg

Kindly please help..


VBA Code:
                           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
 

Attachments

  • 1.jpg
    1.jpg
    139.1 KB · Views: 19
  • 2.jpg
    2.jpg
    138.1 KB · Views: 21
  • 3.jpg
    3.jpg
    139.3 KB · Views: 19

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi ajoy123rocks,

In order to use PasteSpecial, you must specify the XLPasteType enumeration after the PasteSpecial syntax.

Here is a good guide explaining this:

Wellsr.com: VBA-pastespecial-values-formats-formulas-and-more
Explained on microsoft's page here: excel.xlpastetype

A simple example of this can be found the in the code below:

VBA Code:
Sub Paste_Range()
Dim range_to_copy As Range, range_for_pasting As Range
Set range_to_copy = Range("A1:F5")
Set range_for_pasting = Range("A7")

range_to_copy.Copy
range_for_pasting.PasteSpecial Paste:=xlPasteValuesAndNumberFormats
End Sub

VBA Code:
Range("J1:L4").Copy
Range("J7").PasteSpecial xlPasteFormats

Below are the main options:
• xlPasteAll
• xlPasteAllExceptBorders
• xlPasteAllMergingConditionalFormats
• xlPasteAllUsingSourceTheme
• xlPasteColumnWidths
• xlPasteComments
• xlPasteFormats
• xlPasteFormulas
• xlPasteFormulasAndNumberFormats
• xlPasteValidation
• xlPasteValues
• xlPasteValuesAndNumberFormats

For instance, you could try:

VBA Code:
Sheets("DSS").Cells(stored_row, col_num).PasteSpecial xlPasteAll
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,310
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top