Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I recorded these two macros to increment / decrement a date used in a
database query. I assigned them to two buttons that users can use to page through sales activity one day at a time. Now I want to limit the range of dates available. For the NextDate macro, if the resulting date is greater than "today", I want it to revert to "today". For the PrevDate macro, if the resulting date is less than "today -14", it should stay at "today-14". I don't know enough VBA to make it happen (I just use the recorder), but I know there are many here who can do it. Cell B1=1, Cell C1 contains the date being changed. -- Carlos ================================================= Sub NextDate() ' ' NextDate Macro ' Macro recorded 01/12/2006 by Carlos ' ' Range("B1").Select Selection.Copy Range("C1").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd, SkipBlanks _ :=False, Transpose:=False End Sub ---------------------------------------------------------------------------- Sub PrevDate() ' ' PrevDate Macro ' Macro recorded 01/12/2006 by Carlos ' ' Range("B1").Select Selection.Copy Range("C1").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlSubtract, _ SkipBlanks:=False, Transpose:=False End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Here is some revised VBA code: I am changing the cell values directly; do not
need to use the 1 in B1: Sub NextDate() ' ' NextDate Macro ' Range("C1").Value = Range("C1") + 1 If Range("C1").Value Date() Then Range("C1").Value = Date() End Sub Sub PrevDate() ' ' PrevDate Macro ' Range("C1").Value= Range("C1").Value - 1 If Range("C1").Value < (Date() - 14) Then Range("C1").Value = Date() - 14 End Sub -- - K Dales "CarlosAntenna" wrote: I recorded these two macros to increment / decrement a date used in a database query. I assigned them to two buttons that users can use to page through sales activity one day at a time. Now I want to limit the range of dates available. For the NextDate macro, if the resulting date is greater than "today", I want it to revert to "today". For the PrevDate macro, if the resulting date is less than "today -14", it should stay at "today-14". I don't know enough VBA to make it happen (I just use the recorder), but I know there are many here who can do it. Cell B1=1, Cell C1 contains the date being changed. -- Carlos ================================================= Sub NextDate() ' ' NextDate Macro ' Macro recorded 01/12/2006 by Carlos ' ' Range("B1").Select Selection.Copy Range("C1").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd, SkipBlanks _ :=False, Transpose:=False End Sub ---------------------------------------------------------------------------- Sub PrevDate() ' ' PrevDate Macro ' Macro recorded 01/12/2006 by Carlos ' ' Range("B1").Select Selection.Copy Range("C1").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlSubtract, _ SkipBlanks:=False, Transpose:=False End Sub |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks K,
I knew there was a way to do that, but when you use the recorder for macros you can only do so much. -- Carlos "K Dales" wrote in message ... Here is some revised VBA code: I am changing the cell values directly; do not need to use the 1 in B1: Sub NextDate() ' ' NextDate Macro ' Range("C1").Value = Range("C1") + 1 If Range("C1").Value Date() Then Range("C1").Value = Date() End Sub Sub PrevDate() ' ' PrevDate Macro ' Range("C1").Value= Range("C1").Value - 1 If Range("C1").Value < (Date() - 14) Then Range("C1").Value = Date() - 14 End Sub -- - K Dales "CarlosAntenna" wrote: I recorded these two macros to increment / decrement a date used in a database query. I assigned them to two buttons that users can use to page through sales activity one day at a time. Now I want to limit the range of dates available. For the NextDate macro, if the resulting date is greater than "today", I want it to revert to "today". For the PrevDate macro, if the resulting date is less than "today -14", it should stay at "today-14". I don't know enough VBA to make it happen (I just use the recorder), but I know there are many here who can do it. Cell B1=1, Cell C1 contains the date being changed. -- Carlos ================================================= Sub NextDate() ' ' NextDate Macro ' Macro recorded 01/12/2006 by Carlos ' ' Range("B1").Select Selection.Copy Range("C1").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd, SkipBlanks _ :=False, Transpose:=False End Sub -------------------------------------------------------------------------- -- Sub PrevDate() ' ' PrevDate Macro ' Macro recorded 01/12/2006 by Carlos ' ' Range("B1").Select Selection.Copy Range("C1").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlSubtract, _ SkipBlanks:=False, Transpose:=False End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort | Excel Worksheet Functions | |||
MACRO NEEDED | Excel Discussion (Misc queries) | |||
Macro Needed - Please Help! | Excel Programming | |||
Macro needed to Paste Values and prevent Macro operation | Excel Discussion (Misc queries) | |||
Macro needed to Paste Values and prevent Macro operation | Excel Discussion (Misc queries) |