• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Quick coding question?

I have the following code set to give an error message one time if the following requirements are met, however, I forgot that I need to include that this need only run if field F5 is equal to 2. Can someone tell me how I would include that without breaking the rest of my code?


Code:
Private Sub ProjNumbrReq()
'If there is a value greater than 0 in U for this row, and column n for this row
'is blank, and employee has been selected, then show an error message that a project number must be entered or no
'reimbursement will be given.

Static alreadyPrompted As Boolean

    Dim myCell As Range
   
        For Each myCell In .Range("U15:U45")
            If myCell.Value > 0 And .Cells(myCell.row, "N") = "" Then
                MsgBox "Project Number must be provided on each line where reimbursement is being claimed.", vbCritical, "Important:"
                Exit Sub
     
      End If
      Next myCell
   
    End With
End Sub

Private Sub ProjNumbrReq()
'If there is a value greater than 0 in U for this row, and column n for this row
'is blank, and employee has been selected, then show an error message that a project number must be entered or no
'reimbursement will be given.

Static alreadyPrompted As Boolean

    Dim myCell As Range
   
        For Each myCell In .Range("U15:U45")
            If myCell.Value > 0 And .Cells(myCell.row, "N") = "" Then
                MsgBox "Project Number must be provided on each line where reimbursement is being claimed.", vbCritical, "Important:"
                Exit Sub
      
      End If
      Next myCell
   
    End With
End Sub
 
Last edited by a moderator:
Hi ,

The procedure ProjNumbrReq is using the dot notation in the lines of code :
Code:
For Each myCell In .Range("U15:U45")
If myCell.Value > 0 And .Cells(myCell.row, "N") = "" Then

But there is no With clause anywhere in your code ; how is this even working ?

Anyway , if you are calling this procedure from somewhere else , and if the worksheet which contains cell F5 is already open , and you have used a With clause there , you can use :

Code:
If .Range("F5") = 2 Then Call ProjNumbrReq

Narayan
 
Back
Top