VBA if else statement 3 conditions

Lulu4466

New Member
Joined
Jun 13, 2020
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Good afternoon.
I want to determine an amount of pay in local currency according to 3 conditions [frequency of pay]: (daily pay, monthly pay, one-off pay)
If pay is in daily mode, amount of pay is : daily pay = daily pay * 5 * 24
If pay is in montly mode, amount of pay is: montly pay * 6
If pay is one-off pay, amount of pay is: one-off pay

1] My code:

VBA Code:
Sub Fill_in_form()
Dim starting_date_internship As String
Dim interval_type As String
Dim ending_date_internship As Date
Dim number_of_months_to_add As Integer
Dim objectives_and_missions_internship As String
Dim registered_company_name As String
Dim commercial_company_name As String
Dim VATno_number_company As Variant
Dim contact_number_company As Variant
Dim department_internship As String
Dim first_name_supervisor As String
Dim last_name_supervisor As String
Dim Gender_OptionButton1 As OptionButton
Dim gender_supervisor As String
Dim job_title_supervisor As String
Dim email_adress_supervisor As String
Dim professional_phone_number_supervisor As Variant
Dim frequency_of_pay As String



Do
  starting_date_internship = InputBox("Enter starting date internship [DD/MM/YYYY]")
  If Not IsDate(starting_date_internship) Then MsgBox "Enter a valid format for starting date internship DD/MM/YYYY"
Loop While Not IsDate(starting_date_internship)
Range("B2") = starting_date_internship
interval_type = "m"
number_of_months_to_add = InputBox("Enter number of months for the internship")
Range("B3") = number_of_months_to_add
ending_date_internship = DateAdd(interval_type, number_of_months_to_add, starting_date_internship)
Range("B4") = ending_date_internship
objectives_and_missions_internship = InputBox("Enter objectives and missions during internship")
Range("B5") = objectives_and_missions_internship
registered_company_name = InputBox("Enter registered trade name of the company")
Range("B8") = registered_company_name
commercial_company_name = InputBox("Enter commercial name of the company")
Range("B9") = commercial_company_name
Do
    VATno_number_company = InputBox("Please enter the VATno number of the company")
    If Not Len(VATno_number_company) = 10 Then MsgBox VATno_number_company & " is not a 10 digit number"
Loop Until Len(VATno_number_company) = 10
Range("B10") = VATno_number_company
contact_number_company = InputBox("Enter contact number of the company")
Range("B15") = contact_number_company
department_internship = InputBox("Enter department of internship")
Range("B18") = title_internship_supervisor
title_internship_supervisor = InputBox("Enter title of supervisor [Mr. or Mrs.]")
Range("B19") = first_name_supervisor
first_name_supervisor = InputBox("Enter first name of supervisor")
Range("B19") = first_name_supervisor
last_name_supervisor = InputBox("Enter last name name of supervisor")
Range("B20") = last_name_supervisor
If title_internship_supervisor = "Mr." Then gender_supervisor = "M"
  Else
  gender_supervisor = "F"
End If
Range("B21") = gender_supervisor
job_title_supervisor = InputBox("Enter job title of supervisor")
Range("B22") = job_title_supervisor
email_adress_supervisor = InputBox("Enter email adress of supervisor")
Range("B23") = email_adress_supervisor
professional_phone_number_supervisor = InputBox("Enter professionnal phone number of supervisor [+ 45 xx xx xx xx]")
Range("B24") = professional_phone_number_supervisor
frequency_of_pay = InputBox("Enter frequency of pay in local currency [daily, monthly or one-off payment]")
Range("B25") = frequency_of_pay
amount_of_pay_in_local_currency = InputBox("Enter amount of pay in local currency")


End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
@Lulu4466

Maybe like...

VBA Code:
frequency_of_pay = InputBox("Enter frequency of pay in local currency [daily, monthly or one-off payment]")
Range("B25") = frequency_of_pay
amount_of_pay_in_local_currency = InputBox("Enter amount of pay in local currency")

Select Case frequency_of_pay
    Case "daily"
        amount_of_pay_in_local_currency = amount_of_pay_in_local_currency * 5 * 24
    Case "monthly"
        amount_of_pay_in_local_currency = amount_of_pay_in_local_currency * 24
    Case Else
        'Otherwise amount_of_pay_in_local_currency = amount_of_pay_in_local_currency
End Select

Hope that helps.
 
Upvote 0
Works perfectly. Thanks a lot snakehips!

VBA Code:
Sub Fill_in_form()
Dim starting_date_internship As String
Dim interval_type As String
Dim ending_date_internship As Date
Dim number_of_months_to_add As Integer
Dim objectives_and_missions_internship As String
Dim registered_company_name As String
Dim commercial_company_name As String
Dim VATno_number_company As Variant
Dim contact_number_company As Variant
Dim department_internship As String
Dim first_name_supervisor As String
Dim last_name_supervisor As String
Dim Gender_OptionButton1 As OptionButton
Dim gender_supervisor As String
Dim job_title_supervisor As String
Dim email_adress_supervisor As String
Dim professional_phone_number_supervisor As Variant
Dim frequency_of_pay As String



Do
  starting_date_internship = InputBox("2/35: Enter starting date internship [DD/MM/YYYY]")
  If Not IsDate(starting_date_internship) Then MsgBox "Enter a valid format for starting date internship DD/MM/YYYY"
Loop While Not IsDate(starting_date_internship)
Range("B2") = starting_date_internship
interval_type = "m"
number_of_months_to_add = InputBox("3/35: Enter number of months for the internship")
Range("B3") = number_of_months_to_add
ending_date_internship = DateAdd(interval_type, number_of_months_to_add, starting_date_internship)
Range("B4") = ending_date_internship
objectives_and_missions_internship = InputBox("5/35: Enter objectives and missions during internship")
Range("B5") = objectives_and_missions_internship
registered_company_name = InputBox("8/35: Enter registered trade name of the company")
Range("B8") = registered_company_name
commercial_company_name = InputBox("9/35: Enter commercial name of the company")
Range("B9") = commercial_company_name
Do
    VATno_number_company = InputBox("10/35: Please enter the VATno number of the company [Format 8 digits: DK99999999]")
    If Not Len(VATno_number_company) = 10 Then MsgBox VATno_number_company & " is not a 10 digit number"
Loop Until Len(VATno_number_company) = 10
Range("B10") = VATno_number_company
contact_number_company = InputBox("15/35: Enter contact number of the company[+ 45 xx xx xx xx]")
Range("B15") = contact_number_company
department_internship = InputBox("17/35: Enter department of internship")
Range("B18") = title_internship_supervisor
title_internship_supervisor = InputBox("18/35: Enter title of supervisor [Mr. or Mrs.]")
Range("B19") = first_name_supervisor
first_name_supervisor = InputBox("19/35: Enter first name of supervisor")
Range("B19") = first_name_supervisor
last_name_supervisor = InputBox("20/35: Enter last name name of supervisor")
Range("B20") = last_name_supervisor
If title_internship_supervisor = "Mr." Then gender_supervisor = "M" Else gender_supervisor = "F"
Range("B21") = gender_supervisor
job_title_supervisor = InputBox("22/35: Enter job title of supervisor")
Range("B22") = job_title_supervisor
email_adress_supervisor = InputBox("23/35: Enter email adress of supervisor")
Range("B23") = email_adress_supervisor
professional_phone_number_supervisor = InputBox("24/35: Enter professionnal phone number of supervisor [+ 45 xx xx xx xx]")
Range("B24") = professional_phone_number_supervisor
frequency_of_pay = InputBox("25/35: Enter frequency of pay in local currency [daily, monthly or one-off payment]")
Range("B25") = frequency_of_pay
amount_of_pay_in_local_currency = InputBox("26/35: Enter amount of pay in local currency")
Select Case frequency_of_pay
    Case "daily"
        amount_of_pay_in_local_currency = amount_of_pay_in_local_currency * 5 * 24
    Case "monthly"
        amount_of_pay_in_local_currency = amount_of_pay_in_local_currency * 24
    Case Else
        'Otherwise amount_of_pay_in_local_currency = amount_of_pay_in_local_currency
End Select
Range("B26") = amount_of_pay_in_local_currency
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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