Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disappearing eXcel ranges 1

Status
Not open for further replies.

tyhand

Programmer
Jul 3, 2002
186
US
hi all,

I have two named ranges called 'sRange' and 'dRange'.
I've set sRange = Columns("F:F")
I've set dRange = Range("G:G")

The macro i wrote is supposed to copy what's in
sRange (F:F) and paste it to dRange (G:G).

However, if the dRange has any data in any of its cells,
the macro is to select dRange (Range "G:G")
and insert a new column thereby shifting to the right
any data that was in Range "G:G" to Range "H:H"
and leaving Range "G:G" (dRange) empty.

Simple enough. However, the thing is that when I go
to paste the info from sRange (Columns "F:F") to
dRange (Range "G:G"), the data gets pasted to
Range "H:H"! It turns out that Range "H:H" has
somehow become the 'dRange'. How this happen? It's
like my original named range disappeared.

I need for dRange to remain Range ("G:G").
Is there a way to prevent this? I there a way around
it? Is there a different naming convention I must use?
Any help greatly appreciated. Thanks! Peace!

Thank
You
Have
A
Nice
Day
 
tyhand:

Excel keeps the same range of cells so that when you insert a column it moves that range to the next column.

Set your range again after you insert the column to H:H.

Regards, LoNeRaVeR
 
tyhand,

Off the top of my head, I would set dRange (G:G) after you insert a new column, or reset it if you need to use dRange before.

HTH
Mike
 
LoNeRaVeR,

I see "Attack Of The Nearly Simultaneous Postings" has struck again! [wink]

Mike
 
The following should work regardless of what G:G is referred to as :

sRange.Copy Destination:=sRange.Offset(0, 1)

A.C.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top