Hello experts,
I am copying a pivot data from one sheet, and pasting as values to a new sheet, and I also want to keep the formatting, which I am unable to do. The code is given below. It is copying and pasting the data, but not the format. I also tried another way to format the cells, towards the later part of the code, but that formats every cell in the column J, not the specific ones which start with a 'letter'.
PLEASE NOTE: Every time this code gets executed it creates a new sheet and the values from the INVOICE DETAILS sheet is copy pasted to a new sheet, which I am sure you guys would have figured out.
I am copying a pivot data from one sheet, and pasting as values to a new sheet, and I also want to keep the formatting, which I am unable to do. The code is given below. It is copying and pasting the data, but not the format. I also tried another way to format the cells, towards the later part of the code, but that formats every cell in the column J, not the specific ones which start with a 'letter'.
PLEASE NOTE: Every time this code gets executed it creates a new sheet and the values from the INVOICE DETAILS sheet is copy pasted to a new sheet, which I am sure you guys would have figured out.
VBA Code:
Sub Save()
Dim wb As Workbook, ws As Worksheet
ThisWorkbook.Worksheets("Invoice details").Activate
For Each cell In Range("F5")
If cell.Value <> 0 Then
MsgBox ("The values in E4 & E5 are not matching. Please check")
GoTo X
End If
Next
If WorksheetFunction.CountA(Range("E1:E5")) = 0 Then
MsgBox ("The values in E1 to E5 cannot be blank. Please check")
GoTo X
End If
'Copy and Paste to new sheet
Sheets("B Invoice details").Cells.Copy
Sheets.Add(After:=Sheets("Invoice details")).Name = Range("E1").Value
ActiveSheet.Cells.PasteSpecial Paste:=xlPasteValues
ActiveSheet.Cells.PasteSpecial Paste:=xlPasteFormats
Dim c As Range
For Each c In ActiveSheet.UsedRange.Columns("J").Cells
If Left(c.Value, 1) <> "#*" Then
c.Font.Bold = True
Else
End If
Next c
Application.CutCopyMode = False
X:
End Sub
Last edited: