Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I wish to copy a list of entries to a new sheet.
If i use the code below it first copy's cell "b2" and then from the last cell to the first. Now i have a double entry. I want it to end at cell b2, because the first cell has collum headings in it! How do i write the code so that cell b2 is not copied first? kind regards Sjoerd this is my code: Sub CopyUniqueEntries() Dim uniquelist As range Set uniquelist = ActiveSheet.range("A2", "A10000") Sheet1.range("b2", Sheet1.range("b65536").End(xlUp)).AdvancedFilter _ Action:=xlFilterCopy, CopyToRange:=uniquelist.Cells(1, 1), Unique:=True End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Advanced Filter has a requirement that the list have a header, that the
header be included in the list range, and the header will be pasted along with the unique list. Since you start the range at B2, The Filter assumes that is the header and copies it, and then the unique list. This why B2 is copied twice. If you start your Range at B1 to include the header, then B2 will not be duplicated, but the header will be pasted in A2. Either way you define your Filter range, the entry in A2 is unwanted and needs to be deleted after the paste. Also, your Paste To range need only be defined as one cell. Sub CopyUniqueEntries() Dim LastRow As Long LastRow = Cells(Rows.Count, "B").End(xlUp).Row 'last data cell in col B Range("B2:B" & LastRow).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range( _ "A2"), Unique:=True Range("A2").Delete 'removes unwanted header End Sub Mike F "Jumparound" wrote in message oups.com... I wish to copy a list of entries to a new sheet. If i use the code below it first copy's cell "b2" and then from the last cell to the first. Now i have a double entry. I want it to end at cell b2, because the first cell has collum headings in it! How do i write the code so that cell b2 is not copied first? kind regards Sjoerd this is my code: Sub CopyUniqueEntries() Dim uniquelist As range Set uniquelist = ActiveSheet.range("A2", "A10000") Sheet1.range("b2", Sheet1.range("b65536").End(xlUp)).AdvancedFilter _ Action:=xlFilterCopy, CopyToRange:=uniquelist.Cells(1, 1), Unique:=True End Sub |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Watch the word wrap on line 2.
Mike F "Mike Fogleman" wrote in message m... Advanced Filter has a requirement that the list have a header, that the header be included in the list range, and the header will be pasted along with the unique list. Since you start the range at B2, The Filter assumes that is the header and copies it, and then the unique list. This why B2 is copied twice. If you start your Range at B1 to include the header, then B2 will not be duplicated, but the header will be pasted in A2. Either way you define your Filter range, the entry in A2 is unwanted and needs to be deleted after the paste. Also, your Paste To range need only be defined as one cell. Sub CopyUniqueEntries() Dim LastRow As Long LastRow = Cells(Rows.Count, "B").End(xlUp).Row 'last data cell in col B Range("B2:B" & LastRow).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range( _ "A2"), Unique:=True Range("A2").Delete 'removes unwanted header End Sub Mike F "Jumparound" wrote in message oups.com... I wish to copy a list of entries to a new sheet. If i use the code below it first copy's cell "b2" and then from the last cell to the first. Now i have a double entry. I want it to end at cell b2, because the first cell has collum headings in it! How do i write the code so that cell b2 is not copied first? kind regards Sjoerd this is my code: Sub CopyUniqueEntries() Dim uniquelist As range Set uniquelist = ActiveSheet.range("A2", "A10000") Sheet1.range("b2", Sheet1.range("b65536").End(xlUp)).AdvancedFilter _ Action:=xlFilterCopy, CopyToRange:=uniquelist.Cells(1, 1), Unique:=True End Sub |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Include A1 (with the real headers) in your unique list.
Put the advanced filter in B1 (that's where the header will be) Your unique list will be in B2:B### If you don't want the header in column B, then delete that cell (not the row) and shift things up. Jumparound wrote: I wish to copy a list of entries to a new sheet. If i use the code below it first copy's cell "b2" and then from the last cell to the first. Now i have a double entry. I want it to end at cell b2, because the first cell has collum headings in it! How do i write the code so that cell b2 is not copied first? kind regards Sjoerd this is my code: Sub CopyUniqueEntries() Dim uniquelist As range Set uniquelist = ActiveSheet.range("A2", "A10000") Sheet1.range("b2", Sheet1.range("b65536").End(xlUp)).AdvancedFilter _ Action:=xlFilterCopy, CopyToRange:=uniquelist.Cells(1, 1), Unique:=True End Sub -- Dave Peterson |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On 3 sep, 14:50, Dave Peterson wrote:
Include A1 (with the real headers) in your unique list. Put the advanced filter in B1 (that's where the header will be) Your unique list will be in B2:B### If you don't want the header in column B, then delete that cell (not the row) and shift things up. Jumparoundwrote: I wish to copy a list of entries to a new sheet. If i use the code below it first copy's cell "b2" and then from the last cell to the first. Now i have a double entry. I want it to end at cell b2, because the first cell has collum headings in it! How do i write the code so that cell b2 is not copied first? kind regards Sjoerd this is my code: Sub CopyUniqueEntries() Dim uniquelist As range Set uniquelist = ActiveSheet.range("A2", "A10000") Sheet1.range("b2", Sheet1.range("b65536").End(xlUp)).AdvancedFilter _ Action:=xlFilterCopy, CopyToRange:=uniquelist.Cells(1, 1), Unique:=True End Sub -- Dave Peterson- Tekst uit oorspronkelijk bericht niet weergeven - - Tekst uit oorspronkelijk bericht weergeven - Tnx for the answers guys! i figured i could delete the first entry right after copying, so i made a makro to delete fhe first row aftert his one :) but ill try to use your answers too! |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm not sure I understand.
But if you meant that you're not going to add headers and instead just delete that first row (which would have been treated like a header), you may want to be careful. If that's the only entry that appears in the original list, you'd be deleting one of the unique values. I'd either add the headers first, do the advanced filter, then delete the headers. Or check to see if that "header" appears in the list further down before deleting it. Jumparound wrote: <<snipped i figured i could delete the first entry right after copying, so i made a makro to delete fhe first row aftert his one :) but ill try to use your answers too! -- Dave Peterson |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On 4 sep, 17:29, Dave Peterson wrote:
I'm not sure I understand. But if you meant that you're not going to add headers and instead just delete that first row (which would have been treated like a header), you may want to be careful. If that's the only entry that appears in the original list, you'd be deleting one of the unique values. I'd either add the headers first, do the advanced filter, then delete the headers. Or check to see if that "header" appears in the list further down before deleting it. Jumparound wrote: <<snipped i figured i could delete the first entry right after copying, so i made a makro to delete fhe first row aftert his one :) but ill try to use your answers too! -- Dave Peterson Oke, this is what happends... information get exported to excel My macro kicks in. I copy unique values from Sheet1.B:B to Sheet2.A2 (this includes the header.) Then i delete first row (Sheet2.A2 - the header from Sheet1.B1) Then i clear empty spaces Then i sort on name "rest of the code executes" This i a working way, have tested it on several documents. Now im ready to try something else. Code:
Sub CopyUniqueEntries() Dim LastRow As Long LastRow = Cells(Rows.Count, "B").End(xlUp).Row 'last data cell in col B Range("B2:B" & LastRow).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range( _ "A2"), Unique:=True Range("A2").Delete 'removes unwanted header End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Unique entries | New Users to Excel | |||
sum unique entries only | Excel Discussion (Misc queries) | |||
Copy Unique Entries | Excel Worksheet Functions | |||
unique entries | Excel Programming | |||
Unique Entries | Excel Programming |