-
Automating Date Change in a macro
Hey guys, Is there any way to change the date within a macro code? I would like to automate the macro to update sfind and sreplace on a weekly basis. For example, for sfind change from 1/1/1900 to 5/2/2011 and sreplace from 5/2/2011 to 5/9/2011 at first, then every monday, it will update sfind and sreplace from 5/2/2011 to 5/9/2011...5/9/2011 to 5/16/2011 respectively. If possible automating it to run at like 5 am. Thanks.
[VBA]Sub CopyFormula()
Dim ws As Worksheet
Dim sfind As String
Dim sreplace As String
sfind = "1/1/1900"
sreplace = "5/2/2011"
For Each ws In Worksheets
ws.Activate
With ActiveSheet.Cells
Cells.Find(What:=sfind, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=True, SearchFormat:=False).Activate
Selection.Copy
On Error Resume Next
Cells.Find(What:=sreplace, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=True, SearchFormat:=False).Activate
ActiveSheet.Paste
End With
Next ws
End Sub[/VBA]
-
It would be much easier to have the variables get their values from a couple of cells or based on computing from the current date, vs having the code overwrite itself.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules