Can someone please tell me why my copy paste special value is not working in this macro? I have attached the worksheet and the macro name is consolidatesheet.
Thank you for your help.
---------------------------------------
Sub ConsolidateSheets()
Dim TargetSh As Worksheet
Dim DestCell As Range
Dim LastRow As Long
Dim sh As Worksheet
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
' Delete the sheet "SUMMARY" if it exists
Application.DisplayAlerts = False
On Error Resume Next
ActiveWorkbook.Worksheets("SUMMARY").Delete
On Error GoTo 0
Application.DisplayAlerts = True
On Error Resume Next
Set TargetSh = Worksheets("SUMMARY")
On Error GoTo 0
If TargetSh Is Nothing Then
Set TargetSh = Worksheets.Add(before:=Sheets(1))
TargetSh.Name = "SUMMARY"
Else
TargetSh.Cells.Clear
End If
Set DestCell = TargetSh.Range("A1")
Sheet7.Range("TEMPLATE_HEADER").Copy DestCell 'copy header from template
Set DestCell = DestCell.Offset(1, 0)
' copy individual dsm sheets to summary sheet
For Each sh In ThisWorkbook.Sheets
If sh.Name <> "CONTROL-HOSPITAL" And sh.Name <> "HOSPITAL MASTER LIST" And sh.Name <> "UNLISTED HOSPITALS" And sh.Name <> "PSR-GLC LIST" And sh.Name <> "PSR-GLC LIST" And sh.Name <> "SUMMARY" And sh.Name <> "INSTRUCTIONS" And sh.Name <> "TEMPLATE" And sh.Name <> "CONTROL-LIVINGCENTER" Then
LastRow = sh.Range("D50000").End(xlUp).Row
If LastRow > 1 Then
sh.Range(Range("SUMMARY_START_CELL").Address & ":" & sh.Range("F" & LastRow).Address).Copy TargetSh.Range(DestCell.Address)
'Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Set DestCell = DestCell.Offset(LastRow - 8)
End If
End If
Next
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
ActiveSheet.UsedRange.EntireColumn.AutoFit 'AutoFit the column width
Sheets("SUMMARY").Visible = False 'hide sheet
End Sub
Thank you for your help.
---------------------------------------
Sub ConsolidateSheets()
Dim TargetSh As Worksheet
Dim DestCell As Range
Dim LastRow As Long
Dim sh As Worksheet
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
' Delete the sheet "SUMMARY" if it exists
Application.DisplayAlerts = False
On Error Resume Next
ActiveWorkbook.Worksheets("SUMMARY").Delete
On Error GoTo 0
Application.DisplayAlerts = True
On Error Resume Next
Set TargetSh = Worksheets("SUMMARY")
On Error GoTo 0
If TargetSh Is Nothing Then
Set TargetSh = Worksheets.Add(before:=Sheets(1))
TargetSh.Name = "SUMMARY"
Else
TargetSh.Cells.Clear
End If
Set DestCell = TargetSh.Range("A1")
Sheet7.Range("TEMPLATE_HEADER").Copy DestCell 'copy header from template
Set DestCell = DestCell.Offset(1, 0)
' copy individual dsm sheets to summary sheet
For Each sh In ThisWorkbook.Sheets
If sh.Name <> "CONTROL-HOSPITAL" And sh.Name <> "HOSPITAL MASTER LIST" And sh.Name <> "UNLISTED HOSPITALS" And sh.Name <> "PSR-GLC LIST" And sh.Name <> "PSR-GLC LIST" And sh.Name <> "SUMMARY" And sh.Name <> "INSTRUCTIONS" And sh.Name <> "TEMPLATE" And sh.Name <> "CONTROL-LIVINGCENTER" Then
LastRow = sh.Range("D50000").End(xlUp).Row
If LastRow > 1 Then
sh.Range(Range("SUMMARY_START_CELL").Address & ":" & sh.Range("F" & LastRow).Address).Copy TargetSh.Range(DestCell.Address)
'Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Set DestCell = DestCell.Offset(LastRow - 8)
End If
End If
Next
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
ActiveSheet.UsedRange.EntireColumn.AutoFit 'AutoFit the column width
Sheets("SUMMARY").Visible = False 'hide sheet
End Sub