LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default need to make code more efficient (if possible)

That worked brilliantly. Thanks a bunch!


Bernie Deitrick wrote:
See my comments in-line...

HTH,
Bernie
MS Excel MVP

Thanks very much! After a few tweaks it is sorting out the data and
deleting the appropriate rows beautifully. There is still one small
problem however- when I try to delete the helper columns, for some
reason the rows do not delete (I still have the whole list). Also, the
"G" column does not really delete, but keeps its header and the entire
column is filled with #REF indicating some kind of formula error.


Sounds like you are deleting the wrong column - but try my suggestions and see what happens....

Here is the relevant portion of my modified macro:
With Workbooks(nwb).Worksheets(ws)
myRow = .UsedRange.Rows.Count
.Range("G1").Value = "Counter"
.Range("G2").Formula = "=IF(C2=C1,1+G1,0)"
.Range("G2").AutoFill
Destination:=Workbooks(nwb).Worksheets(ws).Range(" G2:G" & myRow)

.Range("H1").Value = "Keep/Delete"
.Range("H2").Formula = "=IF(G3G2,""Delete"",""Keep"")"
.Range("H2").AutoFill
Destination:=Workbooks(nwb).Worksheets(ws).Range(" H2:H" & myRow)


Try changing these two lines below:

.Range(.Cells(2, 8), .Cells(.UsedRange.Rows.Count, 8)).Copy
.Range(.Cells(2, 9), .Cells(.UsedRange.Rows.Count, 9)).PasteSpecial
Paste:=xlValues, _
SkipBlanks:=False, Transpose:=False


to:

.Range("G:H").Copy
.Range("G:H").PasteSpecial Paste:=xlValues

and sort on H rather than I:
key1:=Workbooks(nwb).Worksheets(ws).Range("H2"), _

.Cells.sort _
key1:=Workbooks(nwb).Worksheets(ws).Range("I2"), _
order1:=xlDescending, _
Key2:=NONE, _
Order2:=xlAscending, _
Header:=xlYes


And instead of filtering on H, try

Dim myF As Range

Set myF = Range("H:H").Find("Keep")
Range(myF, myF.End(xlDown)).EntireRow.Delete


Remove this.....
With .Range("I:I")
.AutoFilter Field:=1, Criteria1:="Keep"
.Cells(xlCellTypeVisible).EntireRow.Delete
End With


and try this for the column deletion:

.Range("G:H").Delete


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
making code more efficient timmulla Excel Discussion (Misc queries) 3 January 23rd 07 02:16 PM
Efficient Code GregR Excel Programming 7 June 27th 05 04:09 PM
More Efficient code than this thom hoyle Excel Programming 14 May 11th 05 07:40 AM
Making code more efficient Tommi[_2_] Excel Programming 8 December 13th 03 07:47 PM
More efficient code Rob Bovey Excel Programming 1 July 9th 03 04:46 AM


All times are GMT +1. The time now is 02:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"