PC Review


Reply
Thread Tools Rate Thread

copy a dynamic column range in macro?

 
 
will-d
Guest
Posts: n/a
 
      16th Jan 2008
I have the following code works perfect when I have a dynamic row. The
variants Dayhour and k are calculated resultls from some conditions. This
piece of code copy the dynamic row from column C. The number of cells copied
is Dayhour.

ActiveSheet.Range("C" & k & ":C" & Dayhour + k - 1).Copy

Now things have changed and C is also need to change, becauseI have a data
source in that the sheets named 2005, 2006, 2007, etc and if it is in October
2006, C should be column K in sheet named 2006, and if it is November, C
should be replaced with column L in 2006.

If I input October 1st, 2006 into a variant called myDate:

Worksheets(Year(myDate)).Activate
DmdMonth = Month(myDate)

ActiveSheet.Range(??????? & k & : ?????? & Dayhour + k - 1).Copy

How do I input ????? in this condition?

Thank you very much.
 
Reply With Quote
 
 
 
 
Bernie Deitrick
Guest
Posts: n/a
 
      16th Jan 2008
Will,

ActiveSheet.Cells(k, DmdMonth +1).Resize(Dayhour).Copy

But there is no need for

Worksheets(Year(myDate)).Activate

You could use:

Worksheets(Year(myDate)).Cells(k, DmdMonth +1).Resize(Dayhour).Copy

HTH,
Bernie
MS Excel MVP


"will-d" <will-(E-Mail Removed)> wrote in message
news:EEEBC82A-F2F9-4D5C-AE53-(E-Mail Removed)...
>I have the following code works perfect when I have a dynamic row. The
> variants Dayhour and k are calculated resultls from some conditions. This
> piece of code copy the dynamic row from column C. The number of cells copied
> is Dayhour.
>
> ActiveSheet.Range("C" & k & ":C" & Dayhour + k - 1).Copy
>
> Now things have changed and C is also need to change, becauseI have a data
> source in that the sheets named 2005, 2006, 2007, etc and if it is in October
> 2006, C should be column K in sheet named 2006, and if it is November, C
> should be replaced with column L in 2006.
>
> If I input October 1st, 2006 into a variant called myDate:
>
> Worksheets(Year(myDate)).Activate
> DmdMonth = Month(myDate)
>
> ActiveSheet.Range(??????? & k & : ?????? & Dayhour + k - 1).Copy
>
> How do I input ????? in this condition?
>
> Thank you very much.



 
Reply With Quote
 
will-d
Guest
Posts: n/a
 
      16th Jan 2008
Thank you Bernie!

Before I can try your method, my code for other necessary operations to
activate or select the dynamic sheet name failed: the following code is not
working,

ActiveWorkbook.Worksheets(Year(myDate)).Select

or

ActiveWorkbook.Worksheets(Year(myDate)).Activate

can you please help?

Thank you, Will



"Bernie Deitrick" wrote:

> Will,
>
> ActiveSheet.Cells(k, DmdMonth +1).Resize(Dayhour).Copy
>
> But there is no need for
>
> Worksheets(Year(myDate)).Activate
>
> You could use:
>
> Worksheets(Year(myDate)).Cells(k, DmdMonth +1).Resize(Dayhour).Copy
>
> HTH,
> Bernie
> MS Excel MVP
>
>
> "will-d" <will-(E-Mail Removed)> wrote in message
> news:EEEBC82A-F2F9-4D5C-AE53-(E-Mail Removed)...
> >I have the following code works perfect when I have a dynamic row. The
> > variants Dayhour and k are calculated resultls from some conditions. This
> > piece of code copy the dynamic row from column C. The number of cells copied
> > is Dayhour.
> >
> > ActiveSheet.Range("C" & k & ":C" & Dayhour + k - 1).Copy
> >
> > Now things have changed and C is also need to change, becauseI have a data
> > source in that the sheets named 2005, 2006, 2007, etc and if it is in October
> > 2006, C should be column K in sheet named 2006, and if it is November, C
> > should be replaced with column L in 2006.
> >
> > If I input October 1st, 2006 into a variant called myDate:
> >
> > Worksheets(Year(myDate)).Activate
> > DmdMonth = Month(myDate)
> >
> > ActiveSheet.Range(??????? & k & : ?????? & Dayhour + k - 1).Copy
> >
> > How do I input ????? in this condition?
> >
> > Thank you very much.

>
>
>

 
Reply With Quote
 
Bernie Deitrick
Guest
Posts: n/a
 
      16th Jan 2008
Sorry, you do need to change to a string....

ActiveWorkbook.Worksheets(CStr(Year(mydate))).Select

HTH,
Bernie
MS Excel MVP


"will-d" <(E-Mail Removed)> wrote in message
news:45EAF516-0D9C-409A-87CA-(E-Mail Removed)...
> Thank you Bernie!
>
> Before I can try your method, my code for other necessary operations to
> activate or select the dynamic sheet name failed: the following code is not
> working,
>
> ActiveWorkbook.Worksheets(Year(myDate)).Select
>
> or
>
> ActiveWorkbook.Worksheets(Year(myDate)).Activate
>
> can you please help?
>
> Thank you, Will
>
>
>
> "Bernie Deitrick" wrote:
>
>> Will,
>>
>> ActiveSheet.Cells(k, DmdMonth +1).Resize(Dayhour).Copy
>>
>> But there is no need for
>>
>> Worksheets(Year(myDate)).Activate
>>
>> You could use:
>>
>> Worksheets(Year(myDate)).Cells(k, DmdMonth +1).Resize(Dayhour).Copy
>>
>> HTH,
>> Bernie
>> MS Excel MVP
>>
>>
>> "will-d" <will-(E-Mail Removed)> wrote in message
>> news:EEEBC82A-F2F9-4D5C-AE53-(E-Mail Removed)...
>> >I have the following code works perfect when I have a dynamic row. The
>> > variants Dayhour and k are calculated resultls from some conditions. This
>> > piece of code copy the dynamic row from column C. The number of cells copied
>> > is Dayhour.
>> >
>> > ActiveSheet.Range("C" & k & ":C" & Dayhour + k - 1).Copy
>> >
>> > Now things have changed and C is also need to change, becauseI have a data
>> > source in that the sheets named 2005, 2006, 2007, etc and if it is in October
>> > 2006, C should be column K in sheet named 2006, and if it is November, C
>> > should be replaced with column L in 2006.
>> >
>> > If I input October 1st, 2006 into a variant called myDate:
>> >
>> > Worksheets(Year(myDate)).Activate
>> > DmdMonth = Month(myDate)
>> >
>> > ActiveSheet.Range(??????? & k & : ?????? & Dayhour + k - 1).Copy
>> >
>> > How do I input ????? in this condition?
>> >
>> > Thank you very much.

>>
>>
>>



 
Reply With Quote
 
will-d
Guest
Posts: n/a
 
      16th Jan 2008
Thank you Bernie, everything is working fine! You have a great day. )

"Bernie Deitrick" wrote:

> Sorry, you do need to change to a string....
>
> ActiveWorkbook.Worksheets(CStr(Year(mydate))).Select
>
> HTH,
> Bernie
> MS Excel MVP
>
>
> "will-d" <(E-Mail Removed)> wrote in message
> news:45EAF516-0D9C-409A-87CA-(E-Mail Removed)...
> > Thank you Bernie!
> >
> > Before I can try your method, my code for other necessary operations to
> > activate or select the dynamic sheet name failed: the following code is not
> > working,
> >
> > ActiveWorkbook.Worksheets(Year(myDate)).Select
> >
> > or
> >
> > ActiveWorkbook.Worksheets(Year(myDate)).Activate
> >
> > can you please help?
> >
> > Thank you, Will
> >
> >
> >
> > "Bernie Deitrick" wrote:
> >
> >> Will,
> >>
> >> ActiveSheet.Cells(k, DmdMonth +1).Resize(Dayhour).Copy
> >>
> >> But there is no need for
> >>
> >> Worksheets(Year(myDate)).Activate
> >>
> >> You could use:
> >>
> >> Worksheets(Year(myDate)).Cells(k, DmdMonth +1).Resize(Dayhour).Copy
> >>
> >> HTH,
> >> Bernie
> >> MS Excel MVP
> >>
> >>
> >> "will-d" <will-(E-Mail Removed)> wrote in message
> >> news:EEEBC82A-F2F9-4D5C-AE53-(E-Mail Removed)...
> >> >I have the following code works perfect when I have a dynamic row. The
> >> > variants Dayhour and k are calculated resultls from some conditions. This
> >> > piece of code copy the dynamic row from column C. The number of cells copied
> >> > is Dayhour.
> >> >
> >> > ActiveSheet.Range("C" & k & ":C" & Dayhour + k - 1).Copy
> >> >
> >> > Now things have changed and C is also need to change, becauseI have a data
> >> > source in that the sheets named 2005, 2006, 2007, etc and if it is in October
> >> > 2006, C should be column K in sheet named 2006, and if it is November, C
> >> > should be replaced with column L in 2006.
> >> >
> >> > If I input October 1st, 2006 into a variant called myDate:
> >> >
> >> > Worksheets(Year(myDate)).Activate
> >> > DmdMonth = Month(myDate)
> >> >
> >> > ActiveSheet.Range(??????? & k & : ?????? & Dayhour + k - 1).Copy
> >> >
> >> > How do I input ????? in this condition?
> >> >
> >> > Thank you very much.
> >>
> >>
> >>

>
>
>

 
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
Dynamic copy range LiAD Microsoft Excel Programming 12 2nd Sep 2009 09:36 AM
A macro to copy & paste many rows (a range) to the next column .. genehunter Microsoft Excel New Users 10 21st Apr 2009 07:36 AM
Macro to copy a certain a cell to a dynamic range Frank Situmorang Microsoft Excel Programming 5 14th Mar 2008 04:26 AM
Dynamic range copy. sungen99 Microsoft Excel Programming 1 10th Jun 2005 04:44 PM
Macro Syntax to copy and paste dynamic data based on one column =?Utf-8?B?amJzYW5kMTAwMQ==?= Microsoft Excel Programming 0 17th May 2005 02:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:18 AM.