Please help with using VBA to copy value except duplicates and blank to a specific area

nikan93

New Member
Joined
Jun 13, 2015
Messages
2
Hi all,

Please help me with the VBA code to copy value in the range of C1 to the cell before the first blank cell from workbook A, removed duplicates and blanks, to a specific area starting at F3 in workbook B. Please help to note that we just know the beginning range and don't know the last range of the above "specific area"

Thank you so much for your help.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hello,

does this work as expected?

Code:
Sub Macro2()
    Range("C1").Select
    Range("C1:C" & Range("C" & Rows.Count).End(xlUp).Row).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("I1" _
        ), Unique:=True
    Range("I1:I" & Range("I" & Rows.Count).End(xlUp).Row).Copy
    Windows("Book3").Activate
    Range("F3").PasteSpecial (xlPasteValues)
    Application.CutCopyMode = False
    Windows("Book2").Activate
    Columns("I:I").ClearContents
End Sub

you will need to change workbook names.

It also assumes both workbooks are open, and column I is available in the origin sheet.
 
Upvote 0
Hi onlyadrafter,

There was an error notification like this: "The command could not be completed by using the range specified" and the below line is highlighted when I chose "Debug":

Code:
Range("C1:C" & Range("C" & Rows.Count).End(xlUp).Row).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("I1" _        ), Unique:=True
 
Upvote 0
Hello,

can't replicate the error. What data do you have in Column C?

Code:
Sub Macro2()
    Range("C1").Select
    Range("C1:C" & Range("C" & Rows.Count).End(xlUp).Row).AdvancedFilter Action:=xlFilterCopy, _
    CopyToRange:=Range("I1"), Unique:=True
    Range("I1:I" & Range("I" & Rows.Count).End(xlUp).Row).Copy
    Windows("Book3").Activate
    Range("F3").PasteSpecial (xlPasteValues)
    Application.CutCopyMode = False
    Range("F3:F" & Range("F" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp
    Windows("Book1").Activate
    Columns("I:I").ClearContents
End Sub

this code will clear duplicate blanks, didn't spot that earlier.
 
Upvote 0

Forum statistics

Threads
1,196,052
Messages
6,013,115
Members
441,748
Latest member
MrBigglesworth

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