VBA syntax issue - copying data from one location to another...

Matty

Well-known Member
Joined
Feb 17, 2007
Messages
3,717
Hi,

Anyone any idea why this doesn't work?
Code:
    With Sheet1
    LR = .Range("A" & .Rows.Count).End(xlUp).Row
    With .Range("A2:A" & LR)
        .AdvancedFilter Action:=xlFilterInPlace, Unique:=True
        .Copy Sheet2.Range("B6") [COLOR=red]PasteSpecial Paste:=xlPasteValues[/COLOR]
    End With    
    End With

I want to copy the unique values from Column A in Sheet1 to B6:B? in Sheet2, but I don't want the formatting to come across, hence xlPasteValues. But it doesn't like the xlPasteValues part.

Having Sunday evening brain issues here and can't figure out how to tweak it to deliver what I need.

Any advice welcome!

Thanks,

Matty
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try

Code:
.SpecialCells(xlCellTypeVisible).Copy
Sheet2.Range("B6").PasteSpecial Paste:=xlPasteValues
 
Upvote 0
Matty

You could probably specify the range to copy to as one of the arguments of the advanced filter.
 
Upvote 0
You could probably specify the range to copy to as one of the arguments of the advanced filter.
Hi Norie,

Could you show me an example of how this is done, please? Be good to know for future reference.

Thanks,

Matty
 
Upvote 0
Matty

You need to change the Action argument and add the CopyToRange argument.
Code:
Dim LR As Long
    With Sheet1
        LR = .Range("A" & .Rows.Count).End(xlUp).Row
        .Range("A1:A" & LR).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Sheet2.Range("B6"), Unique:=True
    End With
That will copy values.

However, and I just found this out, it does copy formatting.

Not all formatting though, for example it doesn't copy conditional formatting or column widths.
 
Upvote 0

Forum statistics

Threads
1,224,582
Messages
6,179,670
Members
452,936
Latest member
anamikabhargaw

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