excel vba - Macro run time error -
i have peice of code filters column 0 values , returns rowcount. tried looping on different columns.this macro works small input. have excel sheet 160106 rows. want run macro on . getting run 1004 error.i found following link kind of explains problem http://support.microsoft.com/kb/210684
but not able resolve it. please me. pasting macro below
my sample file in http://rapidshare.com/files/457005707/data1.xlsx 96mb file
option explicit sub findrcn() dim wsstart worksheet dim sword string dim rowcount integer dim long dim j long dim l long dim k string dim final integer dim lastrow integer dim rng range dim obook workbook set wsstart = activesheet 'this loop check if sheet exists j = 1 worksheets.count k = worksheets(j).name if ucase(k) = ucase("analysis") lastrow = ((sheets("analysis").range("a" & rows.count).end(xlup).row) + 1) else lastrow = 0 end if next j msgbox "finished checking sheets" = 1 each rng in range("a1:b1").columns sword = replace(rng.address(rowabsolute:=false), "$", "") ''now trying loop on columns if lastrow = 0 sheets.add after:=sheets(sheets.count) 'adding new sheet sheets(sheets.count).name = "analysis" wsstart.autofiltermode = false wsstart .range(sword).autofilter field:=i, criteria1:="=0" 'if column contains 0 in filter .autofilter.range.columns(1).specialcells(xlcelltypevisible) final = .count 'get count of number of rows after filter rowcount = final - 1 end sheets("analysis").range("a") = rowcount 'paste in analysis tab sheets("analysis").range("b") = (range(sword)) end wsstart.autofiltermode = false msgbox "trust in lord heart , lean not on own understanding; in ways acknowledge him, , make paths straight." & vbcrlf & "proverbs 3:5" & vbcrlf & " completed!!!" else wsstart.autofiltermode = false lastrow = ((sheets("analysis").range("a" & rows.count).end(xlup).row) + 1) wsstart .range(sword).autofilter field:=i, criteria1:="=0" 'if column contains 0 in filter .autofilter.range.columns(1).specialcells(xlcelltypevisible) final = .count rowcount = final - 1 ' account column name end sheets("analysis").range("a" & lastrow) = rowcount 'paste in analysis tab sheets("analysis").range("b" & lastrow) = (range(sword)) end wsstart.autofiltermode = false end if = + 1 next rng
although knowledgebase article talking copying sheets , you're copying cells, follow advice , save , close worksheets periodically.
Comments
Post a Comment