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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic VBA to copy a range if today()

Status
Not open for further replies.

lidcimc

Programmer
Feb 15, 2006
3
US
I need to copy a range (col B:col F) if date in col A is today's date. Then I need to paste that data into col B:col F on another worksheet if col A is today's date.

My goal is maintain a history file in a hidden sheet. Thoughts?
 


Hi,

What code do you have so far?

Where are you stuck?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
This is what I have so far - I get a "400" error after the copy.


Sub CopyRow()
Dim Rng As Range
Dim i As Range

Set Rng = Range("A15", Range("A" & Rows.Count).End(xlUp))
For Each i In Rng
If i = Date Then
i.EntireRow.Copy
Sheets("History Stats").Range("A3" & Rows.Count).End(xlUp)(2). _
EntireRow.PasteSpecial
End If
Next i
End Sub
 


try this...
Code:
Sub CopyRow()
   Dim Rng As Range
   Dim i As Range
   
   Set Rng = Range("A15", Range("A" & Rows.Count).End(xlUp))
   For Each i In Rng
       If i = Date Then
           i.EntireRow.Copy
           With Sheets("History Stats")
                Range(.[A3], .[A3].End(xlDown)).Offset(1).PasteSpecial xlPasteAll
           End With
       End If
   Next i
End Sub


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Getting closer - 1 row copied but the result is 5 duplicate rows pasted - not just the one.

Is there something in this line of code that can be tweaked?

Range(.[A3], .[A3].End(xlDown)).Offset(1).PasteSpecial xlPasteAll

 


Code:
  .[A3].End(xlDown).Offset(1).PasteSpecial xlPasteAll


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top