Copy/Paste values only- Autofilter

aadil_1408

New Member
Joined
Jan 3, 2021
Messages
16
Office Version
  1. 2019
Platform
  1. Windows
Hello,

I have written a code to take value form a sheet (Database) and transfer to another sheet based on owner criteria using auto filter. Is there a way to copy only the values from the database and not formulas as i would like to preserve the copied values.

Attached is the code i am using
1609826177369.png
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
VBA Code:
Sub AadilData()
'
' AadilData Macro
'

'
Dim wsData      As Worksheet
Dim wsDest      As Worksheet
Dim tr As Long

Application.ScreenUpdating = False

Set wsData = Project_Data.Sheets("Database")
Set wsDest = Project_Data.Sheets("Aadil")

tr = wsData.Cells(Rows.Count, "A").End(xlUp).Row
If wsData.FilterMode Then wsData.ShowAllData

With wsData.Rows(1)
    .AutoFilter field:=4, Criteria1:="Aadil"
    If wsData.Range("D1:D" & tr).SpecialCells(xlCellTypeVisible).Cells.Count > 1 Then
        wsData.Range("A2:M" & tr).SpecialCells(xlCellTypeVisible).Copy wsDest.Range("A" & Rows.Count).End(3)(2)
        wsDest.UsedRange.Borders.ColorIndex = xlNone
        wsDest.Select
    End If
    .AutoFilter field:=4
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try the amended code below

VBA Code:
Sub AadilData()
'
' AadilData Macro
'

'
Dim wsData      As Worksheet
Dim wsDest      As Worksheet
Dim tr As Long

Application.ScreenUpdating = False

Set wsData = Project_Data.Sheets("Database")
Set wsDest = Project_Data.Sheets("Aadil")

tr = wsData.Cells(Rows.Count, "A").End(xlUp).Row
If wsData.FilterMode Then wsData.ShowAllData

With wsData.Rows(1)
    .AutoFilter field:=4, Criteria1:="Aadil"
    If wsData.Range("D1:D" & tr).SpecialCells(xlCellTypeVisible).Cells.Count > 1 Then
        wsData.Range("A2:M" & tr).SpecialCells(xlCellTypeVisible).Copy
        wsDest.Range("A" & Rows.Count).End(3)(2).PasteSpecial xlValues
        wsDest.UsedRange.Borders.ColorIndex = xlNone
        wsDest.Select
    End If
    .AutoFilter field:=4
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,701
Messages
6,126,292
Members
449,308
Latest member
VerifiedBleachersAttendee

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