Difficulity identifying the month in a range then proceeding with a calcualtion.

kevin8482

New Member
Joined
Sep 3, 2014
Messages
2
I am fairly new to excel VBA and I am stuck so far. I am attempting to write some code for use with a userform. The logic I would like to use is as follows:



If the calculated number of months = A:A then use the days/hours from Column E, however if any of the months are 6,7,or 8 (June, July or August) then I need to know how many months meet that criteria and use the day/hours from column C for those months + the days/hours from column E for the remaining calculated months. I have included the table below and the code I am currently using. Thanks in advance!

Sub testing()

Dim Start1, Start2, Start3, Start4, End1, End2, End3, End4
Start1 = "6 / 1 / 14"
'Start1 = frmMainPage.Label5.Caption
'Start2 = frmMainPage.Label6.Caption
'Start3 = frmMainPage.Label7.Caption
'Start4 = frmMainPage.Label8.Caption
End1 = "6 / 30 / 14"
'End1 = frmMainPage.Label11.Caption
'End2 = frmMainPage.Label12.Caption
'End3 = frmMainPage.Label13.Caption
'End4 = frmMainPage.Label14.Caption
'MsgBox (Month(End3))
If Start1 = "Select Start Date" Then
MsgBox ("Please select a start date!")
GoTo 2
ElseIf End1 = "Select Start Date" Then
MsgBox ("Please select an end date!")
GoTo 2
Else
GoTo 3
End If
3
'Child 1
Dim dBeginDate As Date
Dim dEndDate As Date
Dim dDate As Date
Dim intMonths, intCalcMth As Integer
' Beginning date.
dBeginDate = DateValue(Start1)
' Ending Date.
dEndDate = DateValue(End1)
' Calculate number of months between dates.
intMonths = ((Year(dEndDate) - Year(dBeginDate)) * 12) + _
Month(dEndDate) - Month(dBeginDate)
' Display number of months.
'MsgBox Str$(intMonths) & " month(s)"
' display number of months of authorizations based on calcualtion
intCalcMth = ((dEndDate - dBeginDate) / 30)
'MsgBox " This authorization is for " & Str$(Round(intCalcMth)) & " month(s)"
'Finds the hours for authorizations
If (Round(intCalcMth)) = Sheet2.Range("A3").Value Then
'checks for summer months
For dDate = dBeginDate To dEndDate
If Format(dDate, "dd") = "01" Then
If Format(dDate, "m") >= 6 And Format(dDate, "m") <= 8 Then
MsgBox ("Summer Months")
End If
End If
Next dDate
Sheet2.Activate
Sheet2.Range("A3").Select
ActiveCell.Offset(0, 4).Select
Days = ActiveCell.Value
hours = ActiveCell.Offset(1, 0).Value
frmMainPage.TextBox1.Value = Str$(Days)
frmMainPage.TextBox8.Value = Str$(hours)
end if
end sub



[TABLE="width: 314"]
<colgroup><col width="64" style="width: 48pt; mso-width-source: userset; mso-width-alt: 2340;"> <col width="105" style="width: 79pt; mso-width-source: userset; mso-width-alt: 3840;"> <col width="88" style="width: 66pt; mso-width-source: userset; mso-width-alt: 3218;"> <col width="82" style="width: 62pt; mso-width-source: userset; mso-width-alt: 2998;"> <col width="79" style="width: 59pt; mso-width-source: userset; mso-width-alt: 2889;"> <tbody>[TR]
[TD="width: 64, bgcolor: transparent"][/TD]
[TD="width: 105, bgcolor: transparent"] [/TD]
[TD="width: 88, bgcolor: transparent"]FULL TIME[/TD]
[TD="width: 82, bgcolor: transparent"]PART TIME[/TD]
[TD="width: 79, bgcolor: transparent"]SCHOOL AGE **[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"][/TD]
[TD="width: 88, bgcolor: transparent"](21 hours of more)[/TD]
[TD="width: 82, bgcolor: transparent"](20 hours or less)
[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]1[/TD]
[TD="width: 105, bgcolor: transparent"]DAYS[/TD]
[TD="width: 88, bgcolor: transparent"]23[/TD]
[TD="width: 82, bgcolor: transparent"]13[/TD]
[TD="width: 79, bgcolor: transparent"]5[/TD]
[/TR]
[TR]
[TD="width: 105, bgcolor: transparent"]HOURS[/TD]
[TD="width: 88, bgcolor: transparent"]138[/TD]
[TD="width: 82, bgcolor: transparent"]115[/TD]
[TD="width: 79, bgcolor: transparent"]92[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]2[/TD]
[TD="width: 105, bgcolor: #EAF1DD"]2 MONTHS[/TD]
[TD="width: 88, bgcolor: #EAF1DD"]46[/TD]
[TD="width: 82, bgcolor: #EAF1DD"]26[/TD]
[TD="width: 79, bgcolor: #EAF1DD"]10[/TD]
[/TR]
[TR]
[TD="width: 105, bgcolor: #EAF1DD"] [/TD]
[TD="width: 88, bgcolor: #EAF1DD"]276[/TD]
[TD="width: 82, bgcolor: #EAF1DD"]230[/TD]
[TD="width: 79, bgcolor: #EAF1DD"]184[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]3[/TD]
[TD="width: 105, bgcolor: transparent"]3 MONTHS[/TD]
[TD="width: 88, bgcolor: transparent"]69[/TD]
[TD="width: 82, bgcolor: transparent"]39[/TD]
[TD="width: 79, bgcolor: transparent"]15[/TD]
[/TR]
[TR]
[TD="width: 105, bgcolor: transparent"] [/TD]
[TD="width: 88, bgcolor: transparent"]414[/TD]
[TD="width: 82, bgcolor: transparent"]345[/TD]
[TD="width: 79, bgcolor: transparent"]276[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]4[/TD]
[TD="width: 105, bgcolor: #EAF1DD"]4 MONTHS[/TD]
[TD="width: 88, bgcolor: #EAF1DD"]92[/TD]
[TD="width: 82, bgcolor: #EAF1DD"]52[/TD]
[TD="width: 79, bgcolor: #EAF1DD"]20[/TD]
[/TR]
[TR]
[TD="width: 105, bgcolor: #EAF1DD"] [/TD]
[TD="width: 88, bgcolor: #EAF1DD"]552[/TD]
[TD="width: 82, bgcolor: #EAF1DD"]460[/TD]
[TD="width: 79, bgcolor: #EAF1DD"]368[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]5[/TD]
[TD="width: 105, bgcolor: transparent"]5 MONTHS[/TD]
[TD="width: 88, bgcolor: transparent"]115[/TD]
[TD="width: 82, bgcolor: transparent"]65[/TD]
[TD="width: 79, bgcolor: transparent"]25[/TD]
[/TR]
[TR]
[TD="width: 105, bgcolor: transparent"] [/TD]
[TD="width: 88, bgcolor: transparent"]690[/TD]
[TD="width: 82, bgcolor: transparent"]575[/TD]
[TD="width: 79, bgcolor: transparent"]460[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]6[/TD]
[TD="width: 105, bgcolor: #EAF1DD"]6 MONTHS[/TD]
[TD="width: 88, bgcolor: #EAF1DD"]138[/TD]
[TD="width: 82, bgcolor: #EAF1DD"]78[/TD]
[TD="width: 79, bgcolor: #EAF1DD"]30[/TD]
[/TR]
[TR]
[TD="width: 105, bgcolor: #EAF1DD"] [/TD]
[TD="width: 88, bgcolor: #EAF1DD"]828[/TD]
[TD="width: 82, bgcolor: #EAF1DD"]690[/TD]
[TD="width: 79, bgcolor: #EAF1DD"]552[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]7[/TD]
[TD="width: 105, bgcolor: transparent"]7 MONTHS[/TD]
[TD="width: 88, bgcolor: transparent"]161[/TD]
[TD="width: 82, bgcolor: transparent"]91[/TD]
[TD="width: 79, bgcolor: transparent"]35[/TD]
[/TR]
[TR]
[TD="width: 105, bgcolor: transparent"] [/TD]
[TD="width: 88, bgcolor: transparent"]966[/TD]
[TD="width: 82, bgcolor: transparent"]805[/TD]
[TD="width: 79, bgcolor: transparent"]644[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]8[/TD]
[TD="width: 105, bgcolor: #EAF1DD"]8 MONTHS[/TD]
[TD="width: 88, bgcolor: #EAF1DD"]184[/TD]
[TD="width: 82, bgcolor: #EAF1DD"]104[/TD]
[TD="width: 79, bgcolor: #EAF1DD"]40[/TD]
[/TR]
[TR]
[TD="width: 105, bgcolor: #EAF1DD"] [/TD]
[TD="width: 88, bgcolor: #EAF1DD"]1104[/TD]
[TD="width: 82, bgcolor: #EAF1DD"]920[/TD]
[TD="width: 79, bgcolor: #EAF1DD"]736[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]9[/TD]
[TD="width: 105, bgcolor: transparent"]9 MONTHS[/TD]
[TD="width: 88, bgcolor: transparent"]207[/TD]
[TD="width: 82, bgcolor: transparent"]117[/TD]
[TD="width: 79, bgcolor: transparent"]45[/TD]
[/TR]
[TR]
[TD="width: 105, bgcolor: transparent"] [/TD]
[TD="width: 88, bgcolor: transparent"]1424[/TD]
[TD="width: 82, bgcolor: transparent"]1035[/TD]
[TD="width: 79, bgcolor: transparent"]828[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]10[/TD]
[TD="width: 105, bgcolor: #EAF1DD"]10 MONTHS[/TD]
[TD="width: 88, bgcolor: #EAF1DD"]230[/TD]
[TD="width: 82, bgcolor: #EAF1DD"]130[/TD]
[TD="width: 79, bgcolor: #EAF1DD"]50[/TD]
[/TR]
[TR]
[TD="width: 105, bgcolor: #EAF1DD"] [/TD]
[TD="width: 88, bgcolor: #EAF1DD"]1380[/TD]
[TD="width: 82, bgcolor: #EAF1DD"]1150[/TD]
[TD="width: 79, bgcolor: #EAF1DD"]920[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]11[/TD]
[TD="width: 105, bgcolor: transparent"]11 MONTHS[/TD]
[TD="width: 88, bgcolor: transparent"]253[/TD]
[TD="width: 82, bgcolor: transparent"]143[/TD]
[TD="width: 79, bgcolor: transparent"]55[/TD]
[/TR]
[TR]
[TD="width: 105, bgcolor: transparent"] [/TD]
[TD="width: 88, bgcolor: transparent"]1518[/TD]
[TD="width: 82, bgcolor: transparent"]1265[/TD]
[TD="width: 79, bgcolor: transparent"]1012[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]12[/TD]
[TD="width: 105, bgcolor: #EAF1DD"]12 MONTHS[/TD]
[TD="width: 88, bgcolor: #EAF1DD"]276[/TD]
[TD="width: 82, bgcolor: #EAF1DD"]156[/TD]
[TD="width: 79, bgcolor: #EAF1DD"]60[/TD]
[/TR]
[TR]
[TD="width: 105, bgcolor: #EAF1DD"] [/TD]
[TD="width: 88, bgcolor: #EAF1DD"]1656[/TD]
[TD="width: 82, bgcolor: #EAF1DD"]1380[/TD]
[TD="width: 79, bgcolor: #EAF1DD"]1104[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"] [/TD]
[TD="width: 105, bgcolor: transparent"]In Home Care[/TD]
[TD="width: 88, bgcolor: transparent"]194[/TD]
[TD="width: 82, bgcolor: transparent"]86[/TD]
[TD="width: 79, bgcolor: transparent"]--------[/TD]
[/TR]
[TR]
[TD="width: 105, bgcolor: transparent"]Hours[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"][/TD]
[TD="width: 354, bgcolor: transparent, colspan: 4"]**School Age: If authorization months cover June, July and/or August use 23 days and 138 hours for each month the authorization is needed for full-time care.

[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,223,237
Messages
6,170,930
Members
452,367
Latest member
TePunaBloke

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