Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Code to copy and paste based on today's date

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 267
Default Code to copy and paste based on today's date

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
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
I'd like to conditionally format a cell based on today's date 0to60 Excel Discussion (Misc queries) 2 August 20th 08 05:59 AM
Need code to copy and paste based on cell address. GoBow777 Excel Discussion (Misc queries) 1 July 13th 08 07:24 AM
Conditional Formatting based on Today's Date MCouture Excel Discussion (Misc queries) 3 May 20th 08 02:46 PM
multiple If's based on today's date dballou Excel Worksheet Functions 5 March 24th 08 03:28 PM
how do you conditional format based upon today's date? valoriegill Excel Worksheet Functions 1 August 22nd 06 12:46 AM


All times are GMT +1. The time now is 07:05 AM.

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

About Us

"It's about Microsoft Excel"