VBA function for 2 criterion

tvanduzee

Board Regular
Joined
Mar 14, 2008
Messages
86
Hello

I have 12 sheets (1 for each month). I use them to record my pay/hrs for each month. We receive an advance on the 15th of each month. In cell A9 on each sheet I have the name of the month.
I am trying to test to see first of all if the current month is the same as the month in cell A9 (no problem), but I also have test to see if the current day is >=15. If it is, then I do a vlookup on the sheet (and use the function created) to put the advance amount in the cell.

Ex:
<code>
Function tstcurmonth(curmonth As String)
Dim LValue As String
Dim x As Date
L = mymonth(curmonth)
x = Date
LValue = MonthName(L, False)
If LValue = ActiveSheet.Range("A9") Then
tstcurmonth = True
Else
tstcurmonth=false
End If
End Function
</code>

This much of the function works fine, but as you can see, I have not tested for the current day (>=15). If both conditions are met, then the function returns true, otherwise it returns false.

In my sheet, I would use it something like this:

<code>
=If(tstcurmonth(A9)=true,vlookup(L17,ADV,2),0)
</code>

Thank you
Terry
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hello

After playing around with it for a while longer, this is what "seems" to work:

<code>
Function tstcurmonth(curmonth As String)
Dim LValue As String
Dim x As Date
L = mymonth(curmonth) 'will return the current month number
x = Date
LValue = MonthName(L, False) 'will return the name of the current month
w = MonthName(DatePart("m", Now))
If LValue = ActiveSheet.Range("A9") And LValue = w And DatePart("d", Now) >= 15 Then
tstcurmonth = True
Else
tstcurmonth = False
End If
End Function

</code>

Just incase there is someone with the same type of issue. Or if there is an easier/more effective way of doing this, please post the alternative.

Thank you
Terry
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,266
Members
452,902
Latest member
Knuddeluff

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