Results 1 to 17 of 17

Thread: Help with a simple VBA

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    VBAX Regular
    Joined
    Nov 2015
    Posts
    9
    Location
    Yay! It's a beauty. I feel like quite the accomplished padawan.



    Dim EmployeeName As String
    Dim OVERTIME As Double
    Dim ABSENT As Double
    Dim X As Integer
    Dim Bonus As Integer
    EmployeeName = InputBox("Enter name")
    OVERTIME = InputBox("Enter hours of overtime")
    ABSENT = InputBox("Enter hours of absenteism")
    X = OVERTIME - 2 * ABSENT / 3
    If X > 40 Then
        Bonus = 50
    ElseIf X > 30 Then
        Bonus = 40
    ElseIf X > 20 Then
        Bonus = 30
    ElseIf X > 10 Then
        Bonus = 20
    Else: Bonus = 10
    End If
    MsgBox ("Bonus payment for " & EmployeeName & " is $" & Bonus)

    OK I know this is probably like teaching a child how to count to 10 when you're an astrophysicist but since we're already here and all, I was wondering if you would mind taking a look at my other assignment? The macro works just fine but it could probably be improved.

    "Write a VBA macro which adds up the numbers from 0 to n. ‘n’ is the input from the user."

    Dim i As Integer, n As Integer
    Dim ans As Integer
    n = InputBox("Enter number")
    ans = 0
    i = 1
    Do While i <= n
        ans = ans + i
        i = i + 1
    Loop
    MsgBox ("Result is" & ans)
    Last edited by Aussiebear; 11-21-2024 at 04:17 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •