ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Moving a range name AND Contents (https://www.excelbanter.com/excel-discussion-misc-queries/238720-moving-range-name-contents.html)

JMay

Moving a range name AND Contents
 
Currently MyRng (a named range) refersto: sheet1 - B2:D4

How can I change that in VBA to sheet2 - D5 (D5:F7)?

I wish to also include the cells B2:D4 values/contents.

How is this done?


FSt1

Moving a range name AND Contents
 
hi
something like this might work.
note your destination range is larger than your source range?????
Sub MoveNamedRange()
Dim r As Range
Set r = Range("MyRng")
Range("MyRng").Copy Destination:= _
Sheets("Sheet2").Range("D5:F7")
ActiveWorkbook.Names.Add Name:="MyRng", _
RefersTo:=Sheets("Sheet2").Range("D5:F7")
r.ClearContents 'optional
End Sub

Regards
FSt1

"JMay" wrote:

Currently MyRng (a named range) refersto: sheet1 - B2:D4

How can I change that in VBA to sheet2 - D5 (D5:F7)?

I wish to also include the cells B2:D4 values/contents.

How is this done?


JMay

Moving a range name AND Contents
 
Thanks for the help Fst1, I got it !!

"FSt1" wrote:

hi
something like this might work.
note your destination range is larger than your source range?????
Sub MoveNamedRange()
Dim r As Range
Set r = Range("MyRng")
Range("MyRng").Copy Destination:= _
Sheets("Sheet2").Range("D5:F7")
ActiveWorkbook.Names.Add Name:="MyRng", _
RefersTo:=Sheets("Sheet2").Range("D5:F7")
r.ClearContents 'optional
End Sub

Regards
FSt1

"JMay" wrote:

Currently MyRng (a named range) refersto: sheet1 - B2:D4

How can I change that in VBA to sheet2 - D5 (D5:F7)?

I wish to also include the cells B2:D4 values/contents.

How is this done?



All times are GMT +1. The time now is 09:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com