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

howard

Well-known Member
Joined
Jun 26, 2006
Messages
5,992
Office Version
  1. 2019
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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

mohadin

Well-known Member
Joined
Mar 22, 2015
Messages
1,091
Office Version
  1. 2013
Platform
  1. Windows
Hi
Try
VBA Code:
   .UsedRange.Copy
'    .UsedRange.PasteSpecial Paste:=xlPasteAllUsingSourceTheme
    .UsedRange.PasteSpecial Paste:=xlPasteValues
    .UsedRange.PasteSpecial Paste:=xlPasteFormats
 

howard

Well-known Member
Joined
Jun 26, 2006
Messages
5,992
Office Version
  1. 2019
Platform
  1. Windows
Thanks for the help, codeworks perfectly
 

mohadin

Well-known Member
Joined
Mar 22, 2015
Messages
1,091
Office Version
  1. 2013
Platform
  1. Windows
You are welcome
And thank you for the feedback
Be happy & safe
 

Forum statistics

Threads
1,140,925
Messages
5,703,183
Members
421,280
Latest member
Jaycee01

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
Top