I have VBA Code below to copy each sheet Range A1 to H500 and paste as values and retaining same format
The code runs very slow (There are 12 sheets)
Kindly amend my code to run faster
Your assistance is most appreciated
The code runs very slow (There are 12 sheets)
Kindly amend my code to run faster
Code:
Sub CopySpecificRangeAndPasteAsValues()
Dim ws As Worksheet
Dim originalCalculationMode As XlCalculation
Dim sourceRange As Range, targetRange As Range
' Set the source range you want to copy (A1 to H500)
Set sourceRange = ThisWorkbook.Sheets(1).Range("A1:H500") ' Adjust the sheet index if needed
' Disable Excel features to improve speed
Application.ScreenUpdating = False
originalCalculationMode = Application.Calculation
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
' Loop through all sheets in the current workbook
For Each ws In ThisWorkbook.Sheets
' Set the target range in the current sheet (A1 to H500)
Set targetRange = ws.Range("A1:H500")
' Copy and paste values while retaining the same format, cell by cell
Dim sourceCell As Range, targetCell As Range
For Each sourceCell In sourceRange
Set targetCell = targetRange.Cells(sourceCell.Row, sourceCell.Column)
sourceCell.Copy
targetCell.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Next sourceCell
Next ws
' Re-enable Excel features and reset calculation mode
Application.CutCopyMode = False ' Clear the clipboard
Application.EnableEvents = True
Application.Calculation = originalCalculationMode
Application.ScreenUpdating = True
End Sub
Your assistance is most appreciated