Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default selecting relative ranges

I'm new to macros and I recorded the following macro in an attempt to learn
how to append items to an ever growing list. I am attempting append 4 copies
of a cell to the end of a column list. I thought I could get to the first
blank cell at the end of the list by going to a blank cell above the list and
selecting "End, Down" twice and then Down. This works fine the first time,
but when I repeat it, the last entry is overwritten. I don't know how to get
the range statement to not be Q8:Q11, but rather a relative address.

Any help would be appreciated.

Sub Copy4()
Selection.Copy
Application.Goto Reference:="R1C17"
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Range("Q8:Q11").Select
ActiveSheet.Paste
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default selecting relative ranges

On Aug 14, 4:04*pm, John Br <John
wrote:
I'm new to macros and I recorded the following macro in an attempt to learn
how to append items to an ever growing list. *I am attempting append 4 copies
of a cell to the end of a column list. *I thought I could get to the first
blank cell at the end of the list by going to a blank cell above the list and
selecting "End, Down" twice and then Down. *This works fine the first time,
but when I repeat it, the last entry is overwritten. *I don't know how to get
the range statement to not be Q8:Q11, but rather a relative address.

Any help would be appreciated.

Sub Copy4()
* * Selection.Copy
* * Application.Goto Reference:="R1C17"
* * Selection.End(xlDown).Select
* * Selection.End(xlDown).Select
* * Range("Q8:Q11").Select
* * ActiveSheet.Paste
End Sub


I am assuming that you want to drop the data in column Q after the
last row containing data. This will copy the contents of the active
cell to the end of column Q

Sub copy4()
Dim CopyTo As Range
Dim CopyFrom As Range
Set CopyTo = Range("Q1").End(xlUp)
Set CopyFrom = ActiveCell
CopyTo.Offset(1, 0).Value = CopyFrom.Value

End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default selecting relative ranges



" wrote:

On Aug 14, 4:04 pm, John Br <John
wrote:
I'm new to macros and I recorded the following macro in an attempt to learn
how to append items to an ever growing list. I am attempting append 4 copies
of a cell to the end of a column list. I thought I could get to the first
blank cell at the end of the list by going to a blank cell above the list and
selecting "End, Down" twice and then Down. This works fine the first time,
but when I repeat it, the last entry is overwritten. I don't know how to get
the range statement to not be Q8:Q11, but rather a relative address.

Any help would be appreciated.

Sub Copy4()
Selection.Copy
Application.Goto Reference:="R1C17"
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Range("Q8:Q11").Select
ActiveSheet.Paste
End Sub


I am assuming that you want to drop the data in column Q after the
last row containing data. This will copy the contents of the active
cell to the end of column Q

Sub copy4()
Dim CopyTo As Range
Dim CopyFrom As Range
Set CopyTo = Range("Q1").End(xlUp)
Set CopyFrom = ActiveCell
CopyTo.Offset(1, 0).Value = CopyFrom.Value

End Sub



Thanks, but it does the same thing as my macro, which is: it overwrites the
previous entry rather than append the second item after the first.
  #4   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default selecting relative ranges

Try:

Sub Copy4()
Selection.Copy Range("Q" & Rows.Count).End(xlUp)(2, 1).Resize(4, 1)
End Sub

Assuming your list will not fill all the way to the bottom of the
spreadsheet it goes to the last row of Column Q and Ctrl-Up to find the last
cell with data in it.

One thing you might change is Selection.Copy to Range("A1").Copy (or
whatever the cell address is - or name the cell and use
Range("NamedRange").Copy).

Chip has a brief discussion on referencing cells in ranges here
http://www.cpearson.com/Excel/cells.htm



"John Br" wrote:

I'm new to macros and I recorded the following macro in an attempt to learn
how to append items to an ever growing list. I am attempting append 4 copies
of a cell to the end of a column list. I thought I could get to the first
blank cell at the end of the list by going to a blank cell above the list and
selecting "End, Down" twice and then Down. This works fine the first time,
but when I repeat it, the last entry is overwritten. I don't know how to get
the range statement to not be Q8:Q11, but rather a relative address.

Any help would be appreciated.

Sub Copy4()
Selection.Copy
Application.Goto Reference:="R1C17"
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Range("Q8:Q11").Select
ActiveSheet.Paste
End Sub

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
Selecting a range relative to an active cell Steve Trombulak Excel Programming 2 March 26th 08 10:05 PM
a twist to relative ranges Ray Pendergast Excel Discussion (Misc queries) 5 February 17th 07 02:08 AM
Selecting a row relative to the position of a button HHall Excel Programming 2 October 14th 05 01:00 AM
Relative cell ranges edm[_2_] Excel Programming 5 April 16th 05 07:53 PM
Specifying ranges relative to a cell Harlan Messinger[_2_] Excel Programming 8 May 21st 04 04:59 PM


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