Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default VBA error Not calculating If then statement

See VBA below. I cannot figure out how to get this to work so that the after
entering in the Name, hours and pay rate for it to calculate the pay and
insert in my worksheet.

Private Sub CommandButtonOk_Click()
If TextBoxEmployeeName.Text = "" Then
MsgBox "You must enter a name."
Exit Sub
End If
NextBlankRow = Application.WorksheetFunction.CountA(Range("ColA") ) + 1
'MsgBox (NextBlankRow)
Cells(NextBlankRow, 1) = TextBoxEmployeeName.Text
Cells(NextBlankRow, 2) = TextBoxHours.Value
Cells(NextBlankRow, 3) = TextBoxPayRate.Value

If (Hours 40) Then
OverTime = Hours - 40
Pay = 40 * PayRate + OverTime * PayRate * 1.5
Else
Pay = 40 * PayRate
End If

TextBoxEmployeeName.Text = ""
TextBoxHours.Value = ""
TextBoxPayRate.Value = ""


TextBoxEmployeeName.SetFocus

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA error Not calculating If then statement

You haven't included any command that would do that. You also haven't
assigned any values to your variables.

Private Sub CommandButtonOk_Click()
Dim pay as Double, OverTime as Double
Dim PayRate as Double, Hours as Double
If TextBoxEmployeeName.Text = "" Then
MsgBox "You must enter a name."
Exit Sub
End If
NextBlankRow = Application.WorksheetFunction.CountA(Range("ColA") ) + 1
'MsgBox (NextBlankRow)
Cells(NextBlankRow, 1) = TextBoxEmployeeName.Text
Cells(NextBlankRow, 2) = TextBoxHours.Value
Cells(NextBlankRow, 3) = TextBoxPayRate.Value

PayRate = Cells(NextBlankRow,3).Value
Hours = Cells(NextBlankRow,2).Value

If (Hours 40) Then
OverTime = Hours - 40
Pay = 40 * PayRate + OverTime * PayRate * 1.5
Else
Pay = 40 * PayRate
End If

Cells(NextBlankRow,4).Value = Pay

TextBoxEmployeeName.Text = ""
TextBoxHours.Value = ""
TextBoxPayRate.Value = ""


TextBoxEmployeeName.SetFocus

End Sub

--
Regards,
Tom Ogilvy

"Marcie" wrote in message
...
See VBA below. I cannot figure out how to get this to work so that the
after
entering in the Name, hours and pay rate for it to calculate the pay and
insert in my worksheet.

Private Sub CommandButtonOk_Click()
If TextBoxEmployeeName.Text = "" Then
MsgBox "You must enter a name."
Exit Sub
End If
NextBlankRow = Application.WorksheetFunction.CountA(Range("ColA") ) + 1
'MsgBox (NextBlankRow)
Cells(NextBlankRow, 1) = TextBoxEmployeeName.Text
Cells(NextBlankRow, 2) = TextBoxHours.Value
Cells(NextBlankRow, 3) = TextBoxPayRate.Value

If (Hours 40) Then
OverTime = Hours - 40
Pay = 40 * PayRate + OverTime * PayRate * 1.5
Else
Pay = 40 * PayRate
End If

TextBoxEmployeeName.Text = ""
TextBoxHours.Value = ""
TextBoxPayRate.Value = ""


TextBoxEmployeeName.SetFocus

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default VBA error Not calculating If then statement

Tom beat me to it. Further to Tom's code, I suggest setting the focus to
TextBoxEmployeeName if no name is selected:
If TextBoxEmployeeName.Text = "" Then
MsgBox "You must enter a name."
TextBoxEmployeeName.SetFocus
Exit Sub
End If

Greg

"Marcie" wrote:

See VBA below. I cannot figure out how to get this to work so that the after
entering in the Name, hours and pay rate for it to calculate the pay and
insert in my worksheet.

Private Sub CommandButtonOk_Click()
If TextBoxEmployeeName.Text = "" Then
MsgBox "You must enter a name."
Exit Sub
End If
NextBlankRow = Application.WorksheetFunction.CountA(Range("ColA") ) + 1
'MsgBox (NextBlankRow)
Cells(NextBlankRow, 1) = TextBoxEmployeeName.Text
Cells(NextBlankRow, 2) = TextBoxHours.Value
Cells(NextBlankRow, 3) = TextBoxPayRate.Value

If (Hours 40) Then
OverTime = Hours - 40
Pay = 40 * PayRate + OverTime * PayRate * 1.5
Else
Pay = 40 * PayRate
End If

TextBoxEmployeeName.Text = ""
TextBoxHours.Value = ""
TextBoxPayRate.Value = ""


TextBoxEmployeeName.SetFocus

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default VBA error Not calculating If then statement

Tom,
Thank you for your help. It worked. I'm new at this and new I needed to
assign something somewhere but wasn't sure. Thanks again.
Marcie

"Tom Ogilvy" wrote:

You haven't included any command that would do that. You also haven't
assigned any values to your variables.

Private Sub CommandButtonOk_Click()
Dim pay as Double, OverTime as Double
Dim PayRate as Double, Hours as Double
If TextBoxEmployeeName.Text = "" Then
MsgBox "You must enter a name."
Exit Sub
End If
NextBlankRow = Application.WorksheetFunction.CountA(Range("ColA") ) + 1
'MsgBox (NextBlankRow)
Cells(NextBlankRow, 1) = TextBoxEmployeeName.Text
Cells(NextBlankRow, 2) = TextBoxHours.Value
Cells(NextBlankRow, 3) = TextBoxPayRate.Value

PayRate = Cells(NextBlankRow,3).Value
Hours = Cells(NextBlankRow,2).Value

If (Hours 40) Then
OverTime = Hours - 40
Pay = 40 * PayRate + OverTime * PayRate * 1.5
Else
Pay = 40 * PayRate
End If

Cells(NextBlankRow,4).Value = Pay

TextBoxEmployeeName.Text = ""
TextBoxHours.Value = ""
TextBoxPayRate.Value = ""


TextBoxEmployeeName.SetFocus

End Sub

--
Regards,
Tom Ogilvy

"Marcie" wrote in message
...
See VBA below. I cannot figure out how to get this to work so that the
after
entering in the Name, hours and pay rate for it to calculate the pay and
insert in my worksheet.

Private Sub CommandButtonOk_Click()
If TextBoxEmployeeName.Text = "" Then
MsgBox "You must enter a name."
Exit Sub
End If
NextBlankRow = Application.WorksheetFunction.CountA(Range("ColA") ) + 1
'MsgBox (NextBlankRow)
Cells(NextBlankRow, 1) = TextBoxEmployeeName.Text
Cells(NextBlankRow, 2) = TextBoxHours.Value
Cells(NextBlankRow, 3) = TextBoxPayRate.Value

If (Hours 40) Then
OverTime = Hours - 40
Pay = 40 * PayRate + OverTime * PayRate * 1.5
Else
Pay = 40 * PayRate
End If

TextBoxEmployeeName.Text = ""
TextBoxHours.Value = ""
TextBoxPayRate.Value = ""


TextBoxEmployeeName.SetFocus

End Sub




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
IF Statement calculating Average if you have numeric & text respon mellermj Excel Worksheet Functions 2 March 4th 09 02:25 PM
Runtime Error - Subscript out of range despite On Error statement DoctorG Excel Programming 3 July 28th 06 03:56 PM
Path/File access error (Error 75) using Name Statement blayne Excel Programming 7 November 22nd 05 09:20 PM
Path/File access error (Error 75) after using Name Statement blayne Excel Programming 0 November 10th 05 12:33 AM
% error calculating grades Marie1uk Excel Worksheet Functions 4 July 2nd 05 03:49 PM


All times are GMT +1. The time now is 06:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"