I got this awesome VBA which does the following from an VBA expert.
Is it possible to operate this code from module instead of pasting it in the source sheet. Also, it appears it is pasting all values greater than 60% also when i use this code. I want to restrict it to only <=60% fields.
Also when there is no value <=60% it has to exit macro and sloe the file. Is this possible?
My previous Message,
VBA Experts,
I have a source sheet and a destination sheet. In the "source" sheet, I have columns A to F. I want to filter column F and select anything <=60% and select the displayed range and paste as value in sheet "Destination".
After doing this, it has to go back to "Source sheet" and unfilter the selection. How can I do this using VBA? Your expertise is appreciated. I have attached the file for reference.
VBA code from the expert below:
--------------------------------------------------
Sub CopyData()
Dim wsSource As Worksheet, wsDest As Worksheet
Dim slr As Long, dlr As Long
Application.ScreenUpdating = False
Set wsSource = Sheets("Source")
Set wsDest = Sheets("Destination")
slr = wsSource.Cells(Rows.Count, 1).End(xlUp).Row
If slr < 4 Then
MsgBox "No data found on Source Sheet.", vbExclamation, "Data Not Found!"
Exit Sub
End If
dlr = wsDest.Cells(Rows.Count, 1).End(xlUp).Row
If dlr > 3 Then wsDest.Range("A3:F" & dlr).Clear
wsSource.AutoFilterMode = False
With wsSource.Rows(3)
.AutoFilter field:=6, Criteria1:="<=0.6"
wsSource.Range("A3:F" & slr).SpecialCells(xlCellTypeVisible).Copy
wsDest.Range("A3").PasteSpecial xlPasteValues
wsDest.Range("A3").PasteSpecial xlPasteFormats
.AutoFilter
End With
wsDest.Activate
Application.ScreenUpdating = True
End Sub
-------------------------------