Using IF Statements with Date

terryhill

New Member
Joined
Jan 23, 2005
Messages
4
Hi,

I have created commandbutton for my sales person to click at the end of each month to tell me that they are finished with their inputs. I am writing a macro to assign to the commandbutton.

My thought is to have a table where Column A is Jan 05, Feb 05, etc. and Column B is the date/time stamp. When the button is pushed, the current date and time will be assigned to the row for the month we are in. So, in March 2005, the sales person clicks the button, and cell in Column B next to the Mar-05 label in Column A receives the date/timestamp.

This is my first try at this macro. When I run this no matter if my computers date is set Jan or Feb, it posts dates into row 15 and row 16.

Anyideas?

Sub AESubmit()
'

Dim amtdate As Date
amtdate = Now()

'January Input
If amtdate >= 1 / 1 / 2005 And amtdate <= 1 / 31 / 2005 Then Worksheets("Sheet1").Activate
Worksheets("Sheet1").Cells(15, 2).Value = Now()


'February Input
If amtdate >= 2 / 1 / 2005 And amtdate <= 2 / 28 / 2005 Then Worksheets("Sheet1").Activate
Worksheets("Sheet1").Cells(16, 2).Value = Now()


End Sub

I'm sure there is a recursive way to do this, but I'm not smart enough to write it. Thanks for insights.

Thanks,

Terry
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hi, welcome to the board!

How about replacing all of that with this:

Code:
Sub AESubmit()
Dim amtdate As Date
amtdate = Now()
Worksheets("Sheet1").Activate
Worksheets("Sheet1").Cells(14 + Month(amtdate), 2).Value = amtdate
End Sub
 

terryhill

New Member
Joined
Jan 23, 2005
Messages
4
Thank you Hotpepper!

Very Nice Improvement. Thank you for the assistance. Wow!

Thanks again!

Terry
 

Forum statistics

Threads
1,148,053
Messages
5,744,528
Members
423,881
Latest member
Nguyen Vu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top