PC Review


Reply
Thread Tools Rate Thread

Code to copy and paste based on today's date

 
 
Code Flunkie
Guest
Posts: n/a
 
      14th Jul 2009
Hi,

I'm new to VBA andI'm having trouble writing a macro to copy rows based on
todays date. I have a macro that inserts todays date in column "P" of sheet1
whenever a change is done on the row. now i'm trying to write a macro that
will, when i save the file, check that column for all entries with todays
date and insert the row from columns A:K on sheet4 in row 2 moving everything
down and then deleting row 102 so i have a list of the last 100 changes with
the newest at the top. below is the attempt i made but it does not work. any
help would be appreciated greatly

Chris

Sub ItemChange()
'
' ItemChange Macro
' copies over any changes in upc list to "Last 100 Changes" on save
'
Sheet4.Range("A2:K" & Rows.Count).ClearContents
Datechk = Today
fLastRow = Sheet1.Range("P" & Rows.Count).End(xlUp).Row
For Each Datechk In Sheet1.Range("P1:P" & fLastRow)
If Date = Datechk Then
NxtRow = NxtRow + 1

Sheet4.Rows("2:2").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
ActiveWindow.SmallScroll Down:=81
Rows("102:102").Select
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=-111
Sheet1.Range("A:K").Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Range("A2:K2").Select
Application.CutCopyMode = False
With Selection.Font
..Name = "Arial"
..Size = 10
..Strikethrough = False
..Superscript = False
..Subscript = False
..OutlineFont = False
..Shadow = False
..Underline = xlUnderlineStyleNone
..ColorIndex = xlAutomatic
..TintAndShade = 0
..ThemeFont = xlThemeFontNone
End With
Range("B2").Select
With Selection.Font
..Name = "Arial"
..Size = 8
..Strikethrough = False
..Superscript = False
..Subscript = False
..OutlineFont = False
..Shadow = False
..Underline = xlUnderlineStyleNone
..ColorIndex = xlAutomatic
..TintAndShade = 0
..ThemeFont = xlThemeFontNone
End With
Range("L2").Select
ActiveCell.FormulaR1C1 = Date


End If
Next

'


End Sub

 
Reply With Quote
 
 
 
 
Atishoo
Guest
Posts: n/a
 
      16th Jul 2009
Make sure that when you enter todays date in the column that it is not
including the time, even if the formating is set to date only the time will
still be included giving it a whole value for date and time hence date and
datechk will never be equal! this could be resolved by integerising the date.

"Code Flunkie" wrote:

> Hi,
>
> I'm new to VBA andI'm having trouble writing a macro to copy rows based on
> todays date. I have a macro that inserts todays date in column "P" of sheet1
> whenever a change is done on the row. now i'm trying to write a macro that
> will, when i save the file, check that column for all entries with todays
> date and insert the row from columns A:K on sheet4 in row 2 moving everything
> down and then deleting row 102 so i have a list of the last 100 changes with
> the newest at the top. below is the attempt i made but it does not work. any
> help would be appreciated greatly
>
> Chris
>
> Sub ItemChange()
> '
> ' ItemChange Macro
> ' copies over any changes in upc list to "Last 100 Changes" on save
> '
> Sheet4.Range("A2:K" & Rows.Count).ClearContents
> Datechk = Today
> fLastRow = Sheet1.Range("P" & Rows.Count).End(xlUp).Row
> For Each Datechk In Sheet1.Range("P1:P" & fLastRow)
> If Date = Datechk Then
> NxtRow = NxtRow + 1
>
> Sheet4.Rows("2:2").Select
> Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
> ActiveWindow.SmallScroll Down:=81
> Rows("102:102").Select
> Selection.Delete Shift:=xlUp
> ActiveWindow.SmallScroll Down:=-111
> Sheet1.Range("A:K").Copy
> Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> SkipBlanks _
> :=False, Transpose:=False
> Range("A2:K2").Select
> Application.CutCopyMode = False
> With Selection.Font
> .Name = "Arial"
> .Size = 10
> .Strikethrough = False
> .Superscript = False
> .Subscript = False
> .OutlineFont = False
> .Shadow = False
> .Underline = xlUnderlineStyleNone
> .ColorIndex = xlAutomatic
> .TintAndShade = 0
> .ThemeFont = xlThemeFontNone
> End With
> Range("B2").Select
> With Selection.Font
> .Name = "Arial"
> .Size = 8
> .Strikethrough = False
> .Superscript = False
> .Subscript = False
> .OutlineFont = False
> .Shadow = False
> .Underline = xlUnderlineStyleNone
> .ColorIndex = xlAutomatic
> .TintAndShade = 0
> .ThemeFont = xlThemeFontNone
> End With
> Range("L2").Select
> ActiveCell.FormulaR1C1 = Date
>
>
> End If
> Next
>
> '
>
>
> End Sub
>

 
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
Return a date range based on today's date BABs Microsoft Access Queries 6 1st Dec 2009 09:40 PM
Outlook Today copy and paste Terry Schmidt Microsoft Outlook Discussion 3 28th Jul 2009 08:46 PM
Need code to copy and paste based on cell address. GoBow777 Microsoft Excel Misc 1 13th Jul 2008 07:24 AM
Attempting to copy/paste data from one worksheet to another (same info but diff layout) based on date criteria tdb770 Microsoft Excel Programming 1 27th Feb 2007 03:17 PM
Outlook today should show tasks based on Start Date, not due date =?Utf-8?B?Um9zZQ==?= Microsoft Outlook Discussion 10 22nd May 2006 09:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:18 PM.