View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default Copy Range and Assign a Defined Name to the Pasted Range

I forgot about naming the range

Sub sonic()
Dim MySelection As Range, SrcRange As Range
Dim DestRange As Range
Set SrcRange = Application.InputBox(prompt:="Select cells to copy", Type:=8)
Set DestRange = Application.InputBox(prompt:="Select top left cell of
destination range", Type:=8)
If Not SrcRange Is Nothing And Not DestRange Is Nothing Then
SrcRange.Copy Destination:=DestRange
ActiveWorkbook.Names.Add Name:="result", _
RefersToR1C1:=DestRange.Resize(SrcRange.Rows.Count , SrcRange.Columns.Count)
Else
MsgBox "You must select the Source and destioantion ranges"
End If
End Sub

Mike

"Mike H" wrote:

Hi,

Try this

Sub sonic()
Dim SrcRange As Range
Dim DestRange As Range
Set SrcRange = Application.InputBox(prompt:="Select cells to copy", Type:=8)
Set DestRange = Application.InputBox(prompt:="Select top left cell of
destination range", Type:=8)
If Not SrcRange Is Nothing And Not DestRange Is Nothing Then
SrcRange.Copy Destination:=DestRange
Else
MsgBox "You must select the Source and destination ranges"
End If
End Sub

Mike

"sgltaylor" wrote:

Hi All,

I need some help with the following:

I am looking for the code which will allow me to copy a range
from one worksheet to another and at the same time assign
a defined name to the pasted area. For example, the range
A1 to A30 on worksheet 2 is copied and pasted to worksheet 1
starting in cell B30. A defined name of "result" is also created
at the same time.

The trick is the worksheets will not always be the same and
neither will the pasted ranges or the address where the
range is to be pasted.

Any help would be greatly appreciated.

Thanks,

Steve
.