View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dudely Dudely is offline
external usenet poster
 
Posts: 21
Default Help Deleting Rows

Thanks but I fail to see any significant difference between your
modified code and my original code. In fact, the ONLY difference that
I see is you're using "Activesheet" to initialize lastRow, whereas I'm
specifically using the named sheet (sht). I wish this newsreader
supported colors so things were easier to see. I also notice that you
- like Chip - also removed the fully qualified reference to cell, and
instead used the "active sheet" function "Range" instead of
"sht.Range" like I do.

So, assuming your code works, then my question remains. Why???

I in fact used Chip's modification to replace my code, in particular I
replaced the line cell.Rows(lastRow).Delete with Rows(lastRow).Delete
and it works. I made NO other changes. So what is the difference
between the two lines of code and why does one work but not the
other???

Thank you


On Oct 21, 3:55*pm, "Don Guillett" wrote:
Sub yoursmodified()
Set sentws = ThisWorkbook.Worksheets("Sent")
* * lastRow = ActiveSheet.UsedRange.Rows.Count 'last row of current sheet
* * currentRow = sentws.UsedRange.Rows.Count 'last row of sent sheet
* * currentRow = currentRow + 1
* * While lastRow 1
* * * * Set cell = Range("A" & lastRow)

* * * * cell.EntireRow.Copy sentws.Range("A" & currentRow)

*' * cell.Rows(lastRow).Delete
* *cell.EntireRow.Delete

* * * * currentRow = currentRow + 1
* * * * lastRow = lastRow - 1
* * Wend
End Sub

'rows 1,2,3 becomes 3,2,1
Sub better() Moves last row from source to 2nd row of new sheet,etc
Set sentws = ThisWorkbook.Worksheets("Sent")
slr = ActiveSheet.UsedRange.Rows.Count
'or slr=cells(rows.count,"a").end(xlup).row
For i = slr To 2 Step -1
dlr = sentws.UsedRange.Rows.Count + 1
'or dlr=sentws.cells(rows.count,"a").end(xlup).row+1
Rows(i).Cut Destination:=sentws.Rows(dlr)
Next i
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
"Dudely" wrote in message

...



I've tried this two different ways, neither seems to work quite right.


* *Set sentWS = ThisWorkbook.Worksheets("Sent")
* *lastRow = sht.UsedRange.Rows.count 'last row of current sheet
* *currentRow = sentWS.UsedRange.Rows.count 'last row of sent sheet
* *currentRow = currentRow + 1
* *While lastRow 1
* * * *Set cell = sht.Range("A" & lastRow)


* * * *cell.EntireRow.Copy sentWS.Range("A" & currentRow)


(1) * *cell.Rows(lastRow).Delete
(2) * *cell.EntireRow.Delete


* * * *currentRow = currentRow + 1
* * * *lastRow = lastRow - 1
* *Wend


The line labeled (1) above fails to do anything at all, and the line
labeled (2) deletes the first line instead of the last line.


The copy works just fine, as does the rest of the code.


So what am I doing wrong please?


Thank you- Hide quoted text -


- Show quoted text -