excel - Sorting using VBA -


i have code below

dim lasteuro long  thisworkbook.sheets("euro cash").range("a2:af").sort key1:=range("t2:t"), order1:=xlascending, key2:=range("v:v"), order2:=xlascending, header:=xlyes  lasteuro = sheets("euro cash").range("a1").end(xldown).row sheets("euro cash").range("a:u").autofilter field:=17, criteria1:=array("lnccp", "lnlchscm"), operator:=xlfiltervalues   'sec no.' sheets("euro cash").range("d2:d" & lasteuro).copy sheets("master").range("k6").pastespecial paste:=xlpastevalues 'cpty name' sheets("euro cash").range("f2:f" & lasteuro).copy sheets("master").range("l6").pastespecial paste:=xlpastevalues 'break' sheets("euro cash").range("i2:i" & lasteuro).copy sheets("master").range("m6").pastespecial paste:=xlpastevalues 'age' sheets("euro cash").range("p2:p" & lasteuro).copy sheets("master").range("p6").pastespecial paste:=xlpastevalues  sheets("euro cash").showalldata 

however upon running, get:

run-time error '1004' : method range of object _global failed.

i clicked on debug, highlights this

thisworkbook.sheets("euro cash").range("a2:af").sort key1:=range("t2:t"), order1:=xlascending, key2:=range("v:v"), order2:=xlascending, header:=xlyes 

so did change thisworkbook.sheets sheets - still same error.. should do?

the use of range object within range .sort method open interpretation parent worksheet is.

dim lasteuro long  sheets("euro cash")     if .autofiltermode .autofiltermode = false     lasteuro = .cells(rows.count, 1).end(xlup).row      .range("a:af").sort key1:=.columns(20), order1:=xlascending, _                         key2:=.columns(22), order2:=xlascending, _                         header:=xlyes      .range("a:u").autofilter field:=17, criteria1:=array("lnccp", "lnlchscm"), _                              operator:=xlfiltervalues     'sec no.'     .range("d2:d" & lasteuro).copy     sheets("master").range("k6").pastespecial paste:=xlpastevalues     'cpty name'     .range("f2:f" & lasteuro).copy     sheets("master").range("l6").pastespecial paste:=xlpastevalues     'break'     .range("i2:i" & lasteuro).copy     sheets("master").range("m6").pastespecial paste:=xlpastevalues     'age'     .range("p2:p" & lasteuro).copy     sheets("master").range("p6").pastespecial paste:=xlpastevalues      if .autofiltermode .autofiltermode = false end 

note use of .range , not range. means parent 1 defined in with ... end statement. required indicate first cell when defining key.

after looking closer @ of code (and reviewing comments provided) i've changed sort range recognizes column header labels in row 1.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -