Help with if statement

yabbadabba

New Member
Joined
Mar 26, 2011
Messages
20
Hi guys, i'm having trouble with my code and the if statement.My code works fine until it gets to to the lines highlighted in red. any help would be appreciated.thanx

Private Sub ListBox3_Click()
Sheets("TimeSheet").Range("E7") = ListBox3.Value
Dim Inp, Outp
Dim Rng As Range
Inp = ListBox3.Value
With Sheets("Rates").Range("A:B")
Set Rng = .Find(what:=Inp, after:=.Cells(.Rows.Count, 1), LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
Outp = Rng.Offset(0, 1).Select
If Sheets("TimeSheet").Range("E7") = "Day Shift" Then
Sheets("TimeSheet").Range("F7") = Val(ActiveCell.Value * 8) + Sheets("Rates").Range("B3") * Val(TextBox48.Value) + Sheets("Rates").Range("B4") * Val(TextBox38.Value)
Else
If Sheets("TimeSheet").Range("E7") = "Afternoon Shift" Then
Sheets("TimeSheet").Range("F7") = Val(ActiveCell.Value * 8) + Sheets("Rates").Range("B6") * Val(TextBox48.Value) + Sheets("Rates").Range("B7") * Val(TextBox38.Value)

End If
End If
End If
End With
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Try

Code:
Private Sub ListBox3_Click()
Sheets("TimeSheet").Range("E7") = ListBox3.Value
Dim Inp, Outp
Dim Rng As Range
Inp = ListBox3.Value
With Sheets("Rates").Range("A:B")
    Set Rng = .Find(what:=Inp, after:=.Cells(.Rows.Count, 1), LookIn:=xlValues, _
    LookAt:=xlPart, _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, _
    MatchCase:=False)
    If Not Rng Is Nothing Then
        Outp = Rng.Offset(0, 1).Select
        If Sheets("TimeSheet").Range("E7") = "Day Shift" Then
            Sheets("TimeSheet").Range("F7") = Val(ActiveCell.Value * 8) + Sheets("Rates").Range("B3") * Val(TextBox48.Value) + Sheets("Rates").Range("B4") * Val(TextBox38.Value)
        ElseIf Sheets("TimeSheet").Range("E7") = "Afternoon Shift" Then
            Sheets("TimeSheet").Range("F7") = Val(ActiveCell.Value * 8) + Sheets("Rates").Range("B6") * Val(TextBox48.Value) + Sheets("Rates").Range("B7") * Val(TextBox38.Value)
        End If
    End If
End With
End Sub
 
Upvote 0
Maybe

Rich (BB code):
Private Sub ListBox3_Click()
Sheets("TimeSheet").Range("E7") = ListBox3.Value
Dim Inp, Outp
Dim Rng As Range
Inp = Val(ListBox3.Value)
With Sheets("Rates").Range("A:B")
    Set Rng = .Find(what:=Inp, after:=.Cells(.Rows.Count, 1), LookIn:=xlValues, _
    LookAt:=xlPart, _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, _
    MatchCase:=False)
    If Not Rng Is Nothing Then
        Rng.Offset(0, 1).Select
        If Sheets("TimeSheet").Range("E7") = "Day Shift" Then
            Sheets("TimeSheet").Range("F7") = Val(ActiveCell.Value * 8) + Sheets("Rates").Range("B3") * Val(TextBox48.Value) + Sheets("Rates").Range("B4") * Val(TextBox38.Value)
        ElseIf Sheets("TimeSheet").Range("E7") = "Afternoon Shift" Then
            Sheets("TimeSheet").Range("F7") = Val(ActiveCell.Value * 8) + Sheets("Rates").Range("B6") * Val(TextBox48.Value) + Sheets("Rates").Range("B7") * Val(TextBox38.Value)
        End If
    Else
        MsgBox "Nothing found"
    End If
End With
End Sub
 
Upvote 0
:-) VoG,Last code didn't work at all except for putting the name of the shift into the cell. First code worked only on the first calculation,and not the second.
 
Upvote 0
I'm not sure what it is supposed to do but as written it will only output one value to one cell. Maybe you need to add a loop?
 
Upvote 0
I do thank you for your patience.basically i need to find the value of a listbox on my sheet called "rates" and multiply it by 8, then i need it to make more calculations based on values in other textboxes. hope this makes sense.thanks

Rates Sheet

Day Shift 25.00
Day Shift Overtime x 1.5 Rate 37.50
Day Shift Overtime x 2 Rate 50.00
Afternoon Shift Rate 28.00
Afternoon Shift Overtime x 1.5 Rate 42.00
Afternoon Shift Overtime x 2 Rate 56.00
Night Shift Rate 32.00
Night Shift Overtime x 1.5 Rate 48.00
Night Shift Overtime x 2 Rate 64.00
Public Holiday Rate 40.00
Public Holiday x 1.5 Rate 60.00
Public Holiday x 2 Rate 80.00
Sick Leave Rate 25.00
Annual Leave Rate 28.00
Salary Sacrifice 300.00
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,839
Members
452,948
Latest member
UsmanAli786

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