PC Review


Reply
Thread Tools Rate Thread

Copy a Range that matches Todays date Q

 
 
Sean
Guest
Posts: n/a
 
      9th Feb 2008
How could I code the following in order to copy the current days
column

I have dates specified in A1:G1 (one of which will be TODAY)
My data for these dates is in A5:G30

I am looking to copy the data who's date (in A1:G1) equals TODAY, to
cells Z1:Z25

Thanks
 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      9th Feb 2008
A bit more clarification on your layout
You could use a for/each loop
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Sean" <(E-Mail Removed)> wrote in message
news:686ef34a-1f11-4adf-b940-(E-Mail Removed)...
> How could I code the following in order to copy the current days
> column
>
> I have dates specified in A1:G1 (one of which will be TODAY)
> My data for these dates is in A5:G30
>
> I am looking to copy the data who's date (in A1:G1) equals TODAY, to
> cells Z1:Z25
>
> Thanks


 
Reply With Quote
 
Sean
Guest
Posts: n/a
 
      9th Feb 2008
Don, layout looks like this

03/02/08 - 04/02/08 - 05/02/08 etc

134 - 762 - 323
32 - 209 - 1234
345 - 549 - 1862
etc - etc

I have a loop code that copies all columns, but above is more like a
lookup, in that if TODAY was 05/02/08 I would only want to copy the
range that shows 323; 1234; 1862 etc
 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      9th Feb 2008
try
Sub copytodayscolumn()
mc = Rows(1).Find(Date).Column
'MsgBox mc
lr = Cells(Rows.Count, mc).End(xlUp).Row
'MsgBox lr
Range(Cells(2, mc), Cells(lr, mc)).Copy Range("z1")
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Sean" <(E-Mail Removed)> wrote in message
news:d0f40851-25dc-45a0-aaf8-(E-Mail Removed)...
> Don, layout looks like this
>
> 03/02/08 - 04/02/08 - 05/02/08 etc
>
> 134 - 762 - 323
> 32 - 209 - 1234
> 345 - 549 - 1862
> etc - etc
>
> I have a loop code that copies all columns, but above is more like a
> lookup, in that if TODAY was 05/02/08 I would only want to copy the
> range that shows 323; 1234; 1862 etc


 
Reply With Quote
 
Sean
Guest
Posts: n/a
 
      9th Feb 2008
Don, thanks, two things on this

My dates are a formula eg. in cell B1is A1+1 etc etc, so the code
can't actually find a valid date. Also where is the 'paste' part in
the code, as I wish to have paste special values

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      9th Feb 2008
If your date in a1 is a date then the b1>>> dates will also be dates so date
will be found.
Please try to FULLY state your problem when you post. You said COPY ("I am
looking to copy"), not paste values. Here is the modification.

Sub copytodayscolumn()
mc = Rows(1).Find(Date).Column
'MsgBox mc
lr = Cells(Rows.Count, mc).End(xlUp).Row
'MsgBox lr
'Range(Cells(2, mc), Cells(lr, mc)).Copy Range("z1")
Range(Cells(2, "z"), Cells(lr, "z")).Value = _
Range(Cells(2, mc), Cells(lr, mc)).Value
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Sean" <(E-Mail Removed)> wrote in message
news:4712f8b1-f7ff-438b-bf66-(E-Mail Removed)...
> Don, thanks, two things on this
>
> My dates are a formula eg. in cell B1is A1+1 etc etc, so the code
> can't actually find a valid date. Also where is the 'paste' part in
> the code, as I wish to have paste special values
>


 
Reply With Quote
 
Sean
Guest
Posts: n/a
 
      10th Feb 2008
My date in A1 is also derived from a formula =TODAY()
+IF(WEEKDAY(TODAY())=1,0,IF(WEEKDAY(TODAY())=2,-1,8-WEEKDAY(TODAY())))

Hence I get a debug error of 'Object variable or With block variable
not set' if I hard code the dates, code works fine, is there a way to
overcme this?
 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      10th Feb 2008
Sub copytodayscolumn()
'set a1
If Weekday(Date) = 1 Then x = 0
If Weekday(Date) = 2 Then x = -1
If Weekday(Date) >= 3 Then x = 8 - Weekday(Date)
Range("a1") = Date + x

mc = Rows(1).Find(Date, LookIn:=xlFormulas).Column
'MsgBox mc
lr = Cells(Rows.Count, mc).End(xlUp).Row
'MsgBox lr
'Range(Cells(2, mc), Cells(lr, mc)).Copy Range("z1")
Range(Cells(2, "e"), Cells(lr, "e")).Value = _
Range(Cells(2, mc), Cells(lr, mc)).Value
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Sean" <(E-Mail Removed)> wrote in message
news:b9f31536-50e4-459c-98ef-(E-Mail Removed)...
> My date in A1 is also derived from a formula =TODAY()
> +IF(WEEKDAY(TODAY())=1,0,IF(WEEKDAY(TODAY())=2,-1,8-WEEKDAY(TODAY())))
>
> Hence I get a debug error of 'Object variable or With block variable
> not set' if I hard code the dates, code works fine, is there a way to
> overcme this?


 
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
How do I subtract todays date from range of dates AHD3 Microsoft Excel Worksheet Functions 1 10th Mar 2010 09:06 PM
Range to find matches to copy values talonega149 Microsoft Excel Programming 5 4th Nov 2009 09:57 PM
Range to find matches to copy values Dwayne Pelletier Microsoft Excel Programming 0 4th Nov 2009 08:07 PM
Todays date in range validator? Tarun Mistry Microsoft ASP .NET 2 22nd Feb 2006 09:33 AM
Date fields automatically updating when field matches todays date!?! Help! Brian Cassin Microsoft Access Forms 1 14th Nov 2003 08:48 PM


Features
 

Advertising
 

Newsgroups
 


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