Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default End (xlDown) question

I want to go to the end of column J, move up two rows, and delete the
last three rows. I'm just not sure how to get the delete range to
vary as I need it to. See code below:

Range("J2").Select
Selection.End(xlDown).Offset(-2, 0).Select
Rows("160:162").Select
Selection.Delete Shift:=xlUp
End Sub

Thanks in advance for your help!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default End (xlDown) question


LastRow = Range("J2").End(xlDown).Offset(-2, 0)
Rows((LastRow - 2) & ":" & LastRow).Delete

"Lotto" wrote:

I want to go to the end of column J, move up two rows, and delete the
last three rows. I'm just not sure how to get the delete range to
vary as I need it to. See code below:

Range("J2").Select
Selection.End(xlDown).Offset(-2, 0).Select
Rows("160:162").Select
Selection.Delete Shift:=xlUp
End Sub

Thanks in advance for your help!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default End (xlDown) question

I made i small mistake

LastRow = Range("J2").End(xlDown).Row
Rows((LastRow - 2) & ":" & LastRow).Delete

If there arre blank cells in column J then use this

LastRow = Range("J" & Rows.Count).End(xlup).Row
Rows((LastRow - 2) & ":" & LastRow).Delete


"Lotto" wrote:

I want to go to the end of column J, move up two rows, and delete the
last three rows. I'm just not sure how to get the delete range to
vary as I need it to. See code below:

Range("J2").Select
Selection.End(xlDown).Offset(-2, 0).Select
Rows("160:162").Select
Selection.Delete Shift:=xlUp
End Sub

Thanks in advance for your help!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default End (xlDown) question

try this:
'============================
Sub delete_J()

Dim myLastRow As Long
Dim myDeleteRange As Range

myLastRow = Worksheets("sheet1") _
.Range("J5000").End(xlUp).Row

Set myDeleteRange = Worksheets("sheet1") _
.Range("J" & myLastRow & ":J" _
& myLastRow - 2)

myDeleteRange.Delete Shift:=xlUp

End Sub
'=======================
worked for me.
:)
susan



On Mar 24, 9:13*am, Lotto wrote:
I want to go to the end of column J, *move up two rows, and delete the
last three rows. *I'm just not sure how to get the delete range to
vary as I need it to. *See code below:

Range("J2").Select
* * Selection.End(xlDown).Offset(-2, 0).Select
* * Rows("160:162").Select
* * Selection.Delete Shift:=xlUp
End Sub

Thanks in advance for your help!


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default End (xlDown) question

This should do what you want...

Worksheets("Sheet1").Cells(Rows.Count, "J").End(xlUp).Offset(-2).Resize(3).EntireRow.Delete

--
Rick (MVP - Excel)


"Lotto" wrote in message ...
I want to go to the end of column J, move up two rows, and delete the
last three rows. I'm just not sure how to get the delete range to
vary as I need it to. See code below:

Range("J2").Select
Selection.End(xlDown).Offset(-2, 0).Select
Rows("160:162").Select
Selection.Delete Shift:=xlUp
End Sub

Thanks in advance for your help!

Reply
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
A1:B(xlDown)? Simon[_2_] Excel Programming 5 July 29th 08 10:23 AM
End(xlDown) not working? RAHokie Excel Discussion (Misc queries) 2 January 19th 07 12:40 AM
xlDown going further than data Astello[_2_] Excel Programming 2 November 15th 06 07:45 PM
End(xlDown) won't work mike Excel Programming 12 September 16th 06 08:50 AM
End(xldown) not always going to last cell? Duncan[_5_] Excel Programming 6 May 4th 06 10:30 AM


All times are GMT +1. The time now is 12:22 PM.

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

About Us

"It's about Microsoft Excel"