Macro to copy data on all sheets and paste as pastespecial retainingthe formats

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have the following macro below when unprotects all the sheets and unhides hidden columns before running the macro to copy the formulas and paste these as values but retaining the formats (Sub ValueCopyCommSheets)

None of the formulas and being copied as values when running the macro "Sub valueCopyCommSheets"


It would be appreciated if someone could assist me




Code:
 Sub UnProtectAll()

   Application.ScreenUpdating = False
Dim i As Long
  
    For i = 1 To Sheets.Count
        Sheets(i).Unprotect
    Next
Application.ScreenUpdating = True

End Sub

Sub UnProtectactive()
With ActiveSheet
           .Unprotect
  End With


End Sub
Sub Unhide_All_Columns_in_Workbook()
    Application.ScreenUpdating = False
  
    UnProtectAll
    Dim i As Long
  
    For i = 1 To Sheets.Count
        Sheets(i).Columns.Hidden = False
    Next
Application.ScreenUpdating = True
UnProtectAll
End Sub



Sub ValueCopyCommSheets()

   Dim i As Long
'Unhide_All_Columns_in_Workbook
      For i = Sheets("southern").Index To Sheets("BR1 EL").Index
      UnProtectAll
      Unhide_All_Columns_in_Workbook
    With Sheets(i)
   '  If .Visible Then
     .UsedRange.Copy
     .UsedRange.PasteSpecial Paste:=xlPasteAllUsingSourceTheme
  'End If
End With
   Next i
   SaveFileasVaues
End Sub


Sub SaveFileasVaues()
ActiveWorkbook.Save

Dim wb As Workbook, OldName$, NewName$
Set wb = ActiveWorkbook
    OldName = wb.Name
    NewName = Left(OldName, InStrRev(OldName, ".") - 1)
    NewName = NewName & " Values.xlsm"

    wb.SaveAs wb.Path & "\" & NewName, wb.FileFormat
    End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi
Try
VBA Code:
   .UsedRange.Copy
'    .UsedRange.PasteSpecial Paste:=xlPasteAllUsingSourceTheme
    .UsedRange.PasteSpecial Paste:=xlPasteValues
    .UsedRange.PasteSpecial Paste:=xlPasteFormats
 
Upvote 0
You are welcome
And thank you for the feedback
Be happy & safe
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,394
Members
448,957
Latest member
Hat4Life

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