Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro- Relative reference

I am trying to record a macro that will copy a certain cell, go to the last
entry in a column and paste the value. I am using Excel 2007. I have been
able to copy and past using the macro but the relative reference function has
not worked. The macro throws and error and visual basic identifies the
second to last line of code as the issue. Here is the code. Does anyone
know how to get around this issue?

Range("D1").Select
Selection.Copy
Range("A1").Select
Selection.End(xlDown).Select
Application.CutCopyMode = False
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=-9

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Macro- Relative reference

You are getting the error because you are setting the CutCopyMode to False
which clears the clipboard, thus you have nothing to paste. Here is some
code that should work for you.


Sub CopyAndPaste()

Dim lngLastRow As Long

' finds last row with data in Col.D
lngLastRow = Cells(Rows.Count, "D").End(xlUp).Row

' copies D1 and paste in last row
Range("D1").Copy Destination:=Range("D" & lngLastRow + 1)

End Sub
--
Cheers,
Ryan


"tb81" wrote:

I am trying to record a macro that will copy a certain cell, go to the last
entry in a column and paste the value. I am using Excel 2007. I have been
able to copy and past using the macro but the relative reference function has
not worked. The macro throws and error and visual basic identifies the
second to last line of code as the issue. Here is the code. Does anyone
know how to get around this issue?

Range("D1").Select
Selection.Copy
Range("A1").Select
Selection.End(xlDown).Select
Application.CutCopyMode = False
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=-9

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
Relative reference? in macro TRYING Excel Worksheet Functions 3 November 20th 07 12:00 AM
Using relative reference in macro Bas Excel Discussion (Misc queries) 0 March 23rd 06 12:11 PM
Relative reference in macro Ricki Miles Excel Programming 3 January 23rd 05 08:51 PM
Relative Reference in a Macro DRH Excel Programming 2 December 31st 04 02:20 PM
MACRO Relative Reference Ibrahim Awwad Excel Programming 3 September 9th 03 02:11 PM


All times are GMT +1. The time now is 06:05 AM.

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"