PasteSpecial how to

owen4512

Board Regular
Joined
Dec 10, 2014
Messages
71
Hi everyone,

The below bit of code will copy then paste dates that are less than or equal to 6 months from today's date. The data on "sheet1" is formatted differently to where the data will be pasted on "sheet2". How can i make it so it will only paste the values and not copying the format too?

Code:
Sub extractDataBasedOnDate()

Dim lastrow As Long, erow As Long, i As Long
Dim mydate As Date
lastrow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
Sheet1.Range("A1").Select


For i = 2 To lastrow


    mydate = Sheet1.Cells(i, 2)
    If mydate <= DateValue(Date) - 6 Then
    erow = Sheet2.Cells(Rows.Count, 3).End(xlUp).Offset(1, 0).Row
    Range(Cells(i, 1), Cells(i, 3)).Copy Destination:=Sheets("sheet2").Cells(erow, 3)
    End If
    
Next i
MsgBox "Complete"


End Sub


Thanks :)
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try
Code:
For i = 2 To LastRow


    mydate = Sheet1.Cells(i, 2)
    If mydate <= DateValue(Date) - 6 Then
    erow = Sheet2.Cells(Rows.Count, 3).End(xlUp).Offset(1, 0).Row
    Sheets("sheet2").Cells(erow, 3).Resize(, 3).Value = Range(Cells(i, 1), Cells(i, 3)).Value
    End If
    
Next i
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,848
Messages
6,127,275
Members
449,372
Latest member
charlottedv

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