Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Referencing the First Cell in Any Selected Range

Macro Goal
After Selecting any range of cells in a first worksheet,
copy contents of the selection
Paste the contents of the selected cells at a second worksheet without using
..paste link:=True.
The cells have to correspond. For instance, content of A2:A4 in the first
worksheet are placed in A2:A4 in the second worksheet. I'm using this
approach for copying formats and values of the selected cells without copying
the entire worksheet.

My approach is not to be specific on calling A2:A4. Therefore using Range
("A2:A4).Select is not an option I need.


I'm trying to get the reference of the first cell in a selected range in the
first worksheet and have the macro automatically move to a second worksheet
and select the first cell corrsonding to the first cell in the selected
range. I hope this make sense.

so far I got this far which pastes the contents starting at the first cell I
last selected in the second worksheet.

Sub copyrangeselected()

Set rng=Selection
rng.copy 'copies cells in my first worksheet
Sheets("Sheet2").Select

Activesheet.Paste

End Sub

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,173
Default Referencing the First Cell in Any Selected Range

Maximouse

I think I understand and this should do what you need

Sub copyrangeselected()
Dim rng As Range
Dim sAddr As String
Set rng = Selection
sAddr = rng.Address
rng.Copy Destination:=Worksheets("Sheet2").Range(sAddr)
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
www.nickhodge.co.uk
HIS


"maximouse" wrote in message
...
Macro Goal
After Selecting any range of cells in a first worksheet,
copy contents of the selection
Paste the contents of the selected cells at a second worksheet without
using
.paste link:=True.
The cells have to correspond. For instance, content of A2:A4 in the first
worksheet are placed in A2:A4 in the second worksheet. I'm using this
approach for copying formats and values of the selected cells without
copying
the entire worksheet.

My approach is not to be specific on calling A2:A4. Therefore using Range
("A2:A4).Select is not an option I need.


I'm trying to get the reference of the first cell in a selected range in
the
first worksheet and have the macro automatically move to a second
worksheet
and select the first cell corrsonding to the first cell in the selected
range. I hope this make sense.

so far I got this far which pastes the contents starting at the first cell
I
last selected in the second worksheet.

Sub copyrangeselected()

Set rng=Selection
rng.copy 'copies cells in my first worksheet
Sheets("Sheet2").Select

Activesheet.Paste

End Sub

Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Referencing the First Cell in Any Selected Range

in this simple example, i have a range called testrange, c6:h16

this this code will give you the address of the upper left cell of the range
called testrange in the immediate window, which is c6


Sub test()
Range("testrange").Select
Debug.Print Range("testrange").Range("A1").Address
End Sub


--


Gary


"maximouse" wrote in message
...
Macro Goal
After Selecting any range of cells in a first worksheet,
copy contents of the selection
Paste the contents of the selected cells at a second worksheet without
using
.paste link:=True.
The cells have to correspond. For instance, content of A2:A4 in the first
worksheet are placed in A2:A4 in the second worksheet. I'm using this
approach for copying formats and values of the selected cells without
copying
the entire worksheet.

My approach is not to be specific on calling A2:A4. Therefore using Range
("A2:A4).Select is not an option I need.


I'm trying to get the reference of the first cell in a selected range in
the
first worksheet and have the macro automatically move to a second
worksheet
and select the first cell corrsonding to the first cell in the selected
range. I hope this make sense.

so far I got this far which pastes the contents starting at the first cell
I
last selected in the second worksheet.

Sub copyrangeselected()

Set rng=Selection
rng.copy 'copies cells in my first worksheet
Sheets("Sheet2").Select

Activesheet.Paste

End Sub

Thanks.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Referencing the First Cell in Any Selected Range

forgot to mention, you don't actually need the Range("testrange").Select
line.
it is just there for illustration purposes when you look at the sheet.


--


Gary


"maximouse" wrote in message
...
Macro Goal
After Selecting any range of cells in a first worksheet,
copy contents of the selection
Paste the contents of the selected cells at a second worksheet without
using
.paste link:=True.
The cells have to correspond. For instance, content of A2:A4 in the first
worksheet are placed in A2:A4 in the second worksheet. I'm using this
approach for copying formats and values of the selected cells without
copying
the entire worksheet.

My approach is not to be specific on calling A2:A4. Therefore using Range
("A2:A4).Select is not an option I need.


I'm trying to get the reference of the first cell in a selected range in
the
first worksheet and have the macro automatically move to a second
worksheet
and select the first cell corrsonding to the first cell in the selected
range. I hope this make sense.

so far I got this far which pastes the contents starting at the first cell
I
last selected in the second worksheet.

Sub copyrangeselected()

Set rng=Selection
rng.copy 'copies cells in my first worksheet
Sheets("Sheet2").Select

Activesheet.Paste

End Sub

Thanks.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Referencing the First Cell in Any Selected Range

Mr. Hodge, you have mastered my question. Gracias.

"Nick Hodge" wrote:

Maximouse

I think I understand and this should do what you need

Sub copyrangeselected()
Dim rng As Range
Dim sAddr As String
Set rng = Selection
sAddr = rng.Address
rng.Copy Destination:=Worksheets("Sheet2").Range(sAddr)
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
www.nickhodge.co.uk
HIS


"maximouse" wrote in message
...
Macro Goal
After Selecting any range of cells in a first worksheet,
copy contents of the selection
Paste the contents of the selected cells at a second worksheet without
using
.paste link:=True.
The cells have to correspond. For instance, content of A2:A4 in the first
worksheet are placed in A2:A4 in the second worksheet. I'm using this
approach for copying formats and values of the selected cells without
copying
the entire worksheet.

My approach is not to be specific on calling A2:A4. Therefore using Range
("A2:A4).Select is not an option I need.


I'm trying to get the reference of the first cell in a selected range in
the
first worksheet and have the macro automatically move to a second
worksheet
and select the first cell corrsonding to the first cell in the selected
range. I hope this make sense.

so far I got this far which pastes the contents starting at the first cell
I
last selected in the second worksheet.

Sub copyrangeselected()

Set rng=Selection
rng.copy 'copies cells in my first worksheet
Sheets("Sheet2").Select

Activesheet.Paste

End Sub

Thanks.




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
Referencing a named range based upon Range name entry in cell Barb Reinhardt Excel Worksheet Functions 14 June 20th 07 07:19 PM
Referencing Row Range in another cell DJS Excel Discussion (Misc queries) 4 January 4th 07 01:12 AM
Referencing a Column in a Selected Range of Columns Rob G Excel Programming 3 October 21st 04 05:21 PM
VBA Referencing a Named Cell Range in another Workbook Frank & Pam Hayes[_2_] Excel Programming 5 June 29th 04 10:01 PM
referencing values in adjacent cells to selected cell Darren Haslett Excel Programming 3 February 23rd 04 05:45 PM


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