Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default Insert a Range

Hello. I am trying to write code that will do an xlendup on a
worksheet to find the last row, and then offset 9 rows up. After I
have the range, copy the range and insert on the next available line.
I tried some code (below) but couldnt get it to work. Any ideas?
Thanks!

lastrow = ActiveSheet.Cells(Cells.Rows.Count, "D").End(xlUp).Row
lastrange = ActiveSheet.Rows(lastrow.Resize(9, 0))

Rows(lastrange).Copy.
Rows(lastrange).Insert Shift:=xlDown

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Insert a Range

Hi Steve

Try this, (I assume you want to copy entire row)

Sub test()
Dim LastRange As Range
LastRow = ActiveSheet.Range("D65536").End(xlUp).Row
Set LastRange = ActiveSheet.Rows(LastRow - 8).Resize(9, 1)

LastRange.EntireRow.Copy
LastRange.Insert Shift:=xlDown
End Sub

Regards,

Per
"Steve" skrev i meddelelsen
...
Hello. I am trying to write code that will do an xlendup on a
worksheet to find the last row, and then offset 9 rows up. After I
have the range, copy the range and insert on the next available line.
I tried some code (below) but couldnt get it to work. Any ideas?
Thanks!

lastrow = ActiveSheet.Cells(Cells.Rows.Count, "D").End(xlUp).Row
lastrange = ActiveSheet.Rows(lastrow.Resize(9, 0))

Rows(lastrange).Copy.
Rows(lastrange).Insert Shift:=xlDown


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Insert a Range

Hi

Just a little thing...

If you only want to copy column D use this line:

Set LastRange = ActiveSheet.Columns(4).Rows(LastRow - 8).Resize(9, 1)

Regards,

Per

"Per Jessen" skrev i meddelelsen
...
Hi Steve

Try this, (I assume you want to copy entire row)

Sub test()
Dim LastRange As Range
LastRow = ActiveSheet.Range("D65536").End(xlUp).Row
Set LastRange = ActiveSheet.Rows(LastRow - 8).Resize(9, 1)

LastRange.EntireRow.Copy
LastRange.Insert Shift:=xlDown
End Sub

Regards,

Per
"Steve" skrev i meddelelsen
...
Hello. I am trying to write code that will do an xlendup on a
worksheet to find the last row, and then offset 9 rows up. After I
have the range, copy the range and insert on the next available line.
I tried some code (below) but couldnt get it to work. Any ideas?
Thanks!

lastrow = ActiveSheet.Cells(Cells.Rows.Count, "D").End(xlUp).Row
lastrange = ActiveSheet.Rows(lastrow.Resize(9, 0))

Rows(lastrange).Copy.
Rows(lastrange).Insert Shift:=xlDown



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default Insert a Range

Hi,

Just another option:

Sub RepCell()
Dim TempRng As Range

Set TempRng = ActiveSheet.Range("D65536").End(xlUp)
TempRng.Offset(1, 0) = TempRng.Offset(-9, 0)
End Sub

Sub RepRow()
Dim TempRng As Range

Set TempRng = ActiveSheet.Range("D65536").End(xlUp).EntireRow
TempRng.Offset(1, 0) = TempRng.Offset(-9, 0).Value
End Sub

The first will just do one cell, the second does the entire row. This
code doesn't actually insert a row, it just copies the values down.
I'm not saying one is better than the other, it just depends what you
want to achieve. Inserting a row will move anything below in other
columns down, while the method in these two won't.

Cheers,
Ivan.

On Apr 1, 6:13*am, "Per Jessen" wrote:
Hi

Just a little thing...

If you only want to copy column D use this line:

Set LastRange = ActiveSheet.Columns(4).Rows(LastRow - 8).Resize(9, 1)

Regards,

Per

"Per Jessen" skrev i . gbl...



Hi Steve


Try this, (I assume you want to copy entire row)


Sub test()
Dim LastRange As Range
LastRow = ActiveSheet.Range("D65536").End(xlUp).Row
Set LastRange = ActiveSheet.Rows(LastRow - 8).Resize(9, 1)


LastRange.EntireRow.Copy
LastRange.Insert Shift:=xlDown
End Sub


Regards,


Per
"Steve" skrev i meddelelsen
...
Hello. *I am trying to write code that will do an xlendup on a
worksheet to find the last row, and then offset 9 rows up. *After I
have the range, copy the range and insert on the next available line.
I tried some code (below) but couldnt get it to work. *Any ideas?
Thanks!


lastrow = ActiveSheet.Cells(Cells.Rows.Count, "D").End(xlUp).Row
lastrange = ActiveSheet.Rows(lastrow.Resize(9, 0))


Rows(lastrange).Copy.
Rows(lastrange).Insert Shift:=xlDown- Hide quoted text -


- Show quoted text -


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
Insert value based on range GL Excel Worksheet Functions 3 October 29th 08 09:04 PM
How to insert from name range into a paragraph? misterno Excel Worksheet Functions 2 March 9th 07 03:52 PM
Auto insert a range fastballfreddy Excel Discussion (Misc queries) 1 May 9th 06 12:41 AM
Insert...Name Range childofthe1980s Excel Discussion (Misc queries) 1 May 24th 05 03:52 PM
Insert a Range name Pete Excel Programming 1 January 14th 04 04:59 PM


All times are GMT +1. The time now is 02:15 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"