1
votes

I have a macro that I made from some examples, to copy values from all other sheets to sheet called "Summary". Values range from column A to M and from row 14 till the end. I'm new to vba and can't figure out how to modify this code, so it would paste only values.

  Sub copy_info()
    Dim i As Long, j As Long, lastRow As Long
    Dim sh As Worksheet
    With Sheets("Summary")
    End With
    j = 14
    For Each sh In ActiveWorkbook.Sheets
    If sh.Name <> "Summary" Then
        lastRow = sh.Cells(sh.Rows.Count, "B").End(xlUp).Row
        For i = 14 To lastRow
            If sh.Range("H" & i) > 0 Then
                sh.Range("A" & i & ":M" & i).Copy     Destination:=Worksheets("Summary").Range("A" & j)
                Sheets("Summary").Range("M" & j) = sh.Name
                j = j + 1
            End If
        Next i
    End If
    Next sh
    Sheets("Summary").Columns("A:M").AutoFit
    End Sub
1

1 Answers

3
votes

Change this line:

sh.Range("A" & i & ":M" & i).Copy     Destination:=Worksheets("Summary").Range("A" & j)

To 2 lines:

sh.Range("A" & i & ":M" & i).Copy     
Worksheets("Summary").Range("A" & j).PasteSpecial xlPasteValues

Alternatively, you could write

Worksheets("Summary").Range("A" & j ":M" & j).Value = sh.Range("A" & i & ":M" & i).Value