Paste Values in VBA

Rob_010101

Board Regular
Joined
Jul 24, 2017
Messages
198
Office Version
  1. 365
Platform
  1. Windows
Hi All,

The following code moves data to an archive sheet, based on the value selected from a list in column P.

It also looks to see if filters have been applied and ensures the data is moved to the next available row, regardless of filtered data.

It works perfectly, however, I'd like the archived row to be values only and not the formulas. Can this be done easily?

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim fromRow%, archiveRow%, archiveList As Worksheet

    If Target.Cells.Count > 1 Then Exit Sub
 
    If Not Application.Intersect(Target, Range("P2:P500000")) Is Nothing Then 'amend this range address to your
        Set archiveList = ThisWorkbook.Worksheets("Archive")
            If Target.Value = "Archive" Then
                fromRow = ActiveCell.Row
              
                With archiveList
                    If .FilterMode Then
                        Dim strMatch As String
                        strMatch = "match" & Replace("(2,1/(a:a>""""),1)", "a:a", .AutoFilter.Range.Cells(1).EntireColumn.Address(0, 0, 1, 1))
                        archiveRow = Evaluate(strMatch) + 1
                    Else
                        archiveRow = archiveList.Cells(archiveList.Rows.Count, 1).End(3).Row + 1
                    End If
                End With
              
                Range(Cells(fromRow, 1), Cells(fromRow, 16)).Copy archiveList.Cells(archiveRow, 1)
                Rows(fromRow).EntireRow.Delete
            End If
    End If
End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Rplace
VBA Code:
Range(Cells(fromRow, 1), Cells(fromRow, 16)).Copy archiveList.Cells(archiveRow, 1)
With
VBA Code:
Range(Cells(fromRow, 1), Cells(fromRow, 16)).Copy
 archiveList.Cells(archiveRow, 1).PasteSpecial Paste:=xlPasteValues
 
Upvote 0
Try changing
VBA Code:
Range(Cells(fromRow, 1), Cells(fromRow, 16)).Copy archiveList.Cells(archiveRow, 1)
to
VBA Code:
Range(Cells(fromRow, 1), Cells(fromRow, 16)).Copy
archiveList.Cells(archiveRow, 1).PasteSpecial xlValues
Application.CutCopyMode = False

or

VBA Code:
    With Range(Cells(fromRow, 1), Cells(fromRow, 16))
        archiveList.Cells(archiveRow, 1).Resize(.Rows.Count, .Columns.Count).Value = .Value
    End With
 
Upvote 0
Solution
Perhaps like this
VBA Code:
                Range(Cells(fromRow, 1), Cells(fromRow, 16)).Copy
                archiveList.Cells(archiveRow, 1).PasteSpecial xlValues
                Application.CutCopyMode = False
                Rows(fromRow).EntireRow.Delete
 
Upvote 0
Rplace
VBA Code:
Range(Cells(fromRow, 1), Cells(fromRow, 16)).Copy archiveList.Cells(archiveRow, 1)
With
VBA Code:
Range(Cells(fromRow, 1), Cells(fromRow, 16)).Copy
 archiveList.Cells(archiveRow, 1).PasteSpecial Paste:=xlPasteValues
Thank you :)
 
Upvote 0
Try changing
VBA Code:
Range(Cells(fromRow, 1), Cells(fromRow, 16)).Copy archiveList.Cells(archiveRow, 1)
to
VBA Code:
Range(Cells(fromRow, 1), Cells(fromRow, 16)).Copy
archiveList.Cells(archiveRow, 1).PasteSpecial xlValues
Application.CutCopyMode = False

or

VBA Code:
    With Range(Cells(fromRow, 1), Cells(fromRow, 16))
        archiveList.Cells(archiveRow, 1).Resize(.Rows.Count, .Columns.Count).Value = .Value
    End With
Yes, this one worked the best.

Thank you very much :)
 
Upvote 0
Perhaps like this
VBA Code:
                Range(Cells(fromRow, 1), Cells(fromRow, 16)).Copy
                archiveList.Cells(archiveRow, 1).PasteSpecial xlValues
                Application.CutCopyMode = False
                Rows(fromRow).EntireRow.Delete
Thank you :)
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,179
Members
452,615
Latest member
bogeys2birdies

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