Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Assign copied range to a variable

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Assign copied range to a variable

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Assign copied range to a variable

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Assign copied range to a variable

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
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
VBA Excel how to assign name in variable range Mouimet Excel Programming 4 November 14th 08 05:56 PM
range variable won't assign (chartobject.topleftcell property) Matthew Dodds Excel Programming 2 November 16th 05 02:25 PM
How to assign a variable in a range select Paul Excel Programming 5 June 3rd 05 11:50 PM
How can I assign a range starting cell based on a variable locati. feman007 Excel Discussion (Misc queries) 1 March 9th 05 11:41 PM
How can I assign a range starting cell based on a variable locati. feman007 Excel Worksheet Functions 3 March 9th 05 11:40 PM


All times are GMT +1. The time now is 01:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"