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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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
 
Upvote 0

Forum statistics

Threads
1,222,149
Messages
6,164,238
Members
451,882
Latest member
Bigtop

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
Back
Top