PC Review


Reply
Thread Tools Rate Thread

Assign copied range to a variable

 
 
johnmasvou
Guest
Posts: n/a
 
      19th Mar 2009
Hi,
I would like to assign a copied range to a variable.
Note: Sth like Set rngCopied=Selection will not always work because my
selected range and copied range might be different.
Thx
 
Reply With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      19th Mar 2009
Just dim some range variables and assign them:

Sub demo()
Dim CopiedRangeSource As Range
Dim CopiedRangeDestination As Range
Set CopiedRangeSource = Range("A1:A100")
Set CopiedRangeDestination = Range("Z100")
CopiedRangeSource.Copy CopiedRangeDestination
End Sub
--
Gary''s Student - gsnu200840


"johnmasvou" wrote:

> Hi,
> I would like to assign a copied range to a variable.
> Note: Sth like Set rngCopied=Selection will not always work because my
> selected range and copied range might be different.
> Thx

 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      19th Mar 2009
I am not sure I follow your logic. As you write your code, you should know
what you intend to copy, so it is easy enough to set it to an object variable
at the time you determine you want to copy. If you have a variable range,
then use the last row and/or last column techniques to get the current size
of the range. Or you can use the resize method in some cases. There are
several options.



"johnmasvou" wrote:

> Hi,
> I would like to assign a copied range to a variable.
> Note: Sth like Set rngCopied=Selection will not always work because my
> selected range and copied range might be different.
> Thx

 
Reply With Quote
 
johnmasvou
Guest
Posts: n/a
 
      20th Mar 2009
Thanks for the reply

Actually, it is not very convenient to copy paste somewhere in the workbook.
The issue is that I have a new workbook event procedure which ultimately
clears the cliboard every time I open a new workbook. Hence, what I would
like to have is sth like:
In my event procedure it should check whether application.cutcopymode=True
and in which case it should assign the copied range to a variable e.g.
rngCopied. Then, after the event procedure has finished, it should re-copy
the rngCopied range.
Is that possible?

Thx

"Gary''s Student" wrote:

> Just dim some range variables and assign them:
>
> Sub demo()
> Dim CopiedRangeSource As Range
> Dim CopiedRangeDestination As Range
> Set CopiedRangeSource = Range("A1:A100")
> Set CopiedRangeDestination = Range("Z100")
> CopiedRangeSource.Copy CopiedRangeDestination
> End Sub
> --
> Gary''s Student - gsnu200840
>
>
> "johnmasvou" wrote:
>
> > Hi,
> > I would like to assign a copied range to a variable.
> > Note: Sth like Set rngCopied=Selection will not always work because my
> > selected range and copied range might be different.
> > Thx

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Paste copied data to specified sheet based on range - variable iss fishy Microsoft Excel Programming 6 1st Apr 2010 02:00 PM
Assign range to variable for sort Michael Conroy Microsoft Excel Programming 2 11th Nov 2009 06:48 AM
assign variable to a range Alberto Ast Microsoft Excel Programming 1 23rd Oct 2009 03:01 AM
VBA Excel how to assign name in variable range Mouimet Microsoft Excel Programming 4 14th Nov 2008 05:56 PM
How to assign a variable in a range select Paul Microsoft Excel Programming 5 3rd Jun 2005 11:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:46 PM.