Lookup Problem

magurto

New Member
Joined
Oct 20, 2017
Messages
3
CAn you please have a look on my code and tell me what is missing?

Code:
Private Sub cmdProcess_Click()

Dim z As Long
Dim UserName As Variant
Dim NameLookup As Variant
Dim strPName As String
Dim sFindIt As String
Dim iFoundPass As Integer

sFindIt = PayoutFrm.txtSerial.Value

If PayoutFrm.cboReceiptType.Value = "VOID" Then MsgBox ("Note all voids require the Casino Manager or Asst. Casino Manager's signature"), vbOKOnly, "Signature required"

On Error Resume Next
With Sheets("Security").Range("A1:A10")

   iFoundPass = .Find(What:=PayoutFrm.cboUserName.Value, After:=.Cells(1, 1), LookIn:=xlValues, LookAt _
        :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False).Row
End With
On Error GoTo 0

If iFoundPass = 0 Then
   SomethingWrong
      Exit Sub
End If

If Sheets("Security").Cells(iFoundPass, 3) <> txtPassword Then
   SomethingWrong
      Exit Sub
End If

    With Sheets("Log Sheet").Range("A:A").Cells.Find(What:=sFindIt, After:=Cells(10, 1), LookIn:=xlValues, _
                 LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, _
                 SearchFormat:=False).Row
  
    
        If Cells(, 28).Value > 0 Then _
            MsgBox ("This bet has already been processed. Please select another bet"), vbCritical Or vbOKOnly
        If Cells(, 28).Value > 0 Then Exit Sub
        
        If PayoutFrm.cboReceiptType.Value = "WINNER" And Sheets("Log Sheet").Cells(, 22).Value <> "Winner" Then _
            MsgBox ("This bet is not a winning bet"), vbCritical Or vbOKOnly
        If PayoutFrm.cboReceiptType.Value = "WINNER" And Sheets("Log Sheet").Cells(, 22).Value <> "Winner" Then Exit Sub
  End With

    With PayoutFrm

        If .txtSerial = "" Then
            MsgBox "Please input a serial number", vbCritical Or vbOKOnly
        If .cboReceiptType = "" Then Exit Sub
        End If
        If .cboUserName = "" Then
            MsgBox "Please select a user before proceeding", vbCritical Or vbOKOnly
        If .cboUserName = "" Then Exit Sub
        End If
        If .cboReceiptType = "" Then
            MsgBox "Please select a receipt type before proceeding", vbCritical Or vbOKOnly
        If .cboReceiptType = "" Then Exit Sub
        End If

    End With

If PayoutFrm.cboReceiptType.Value = "WINNER" And Sheets("Log Sheet").Cells(, 22).Value = "" Then MsgBox ("Please enter the game result on the log sheet before proceeding")
If PayoutFrm.cboReceiptType.Value = "WINNER" And Sheets("Log Sheet").Cells(, 22).Value = "" Then Exit Sub


strPName = Application.ActivePrinter ' Gets default printer name
'Set NameLookup = Sheets("Menu").Range("K4:K12")

'On Error Resume Next
'Err.Clear

'UserName = Application.WorksheetFunction.VLookup(cboUserName.Text, NameLookup, 2, False)

Application.ScreenUpdating = False

PrintFrm.Show

Sheets("Audit Log").Visible = True
Sheets("Audit Log").Select
ActiveSheet.Unprotect Password:="miami"

        With ActiveSheet.[A2:D501]
            For z = .Rows.Count To 1 Step -1
                If .Cells(z, 1) & .Cells(z, 2) & .Cells(z, 3) & .Cells(z, 4) <> "" Then Exit For
            Next
                .Cells(z + 1, 1) = Now()
                .Cells(z + 1, 2) = cboUserName.Text
                .Cells(z + 1, 3) = UserName
                .Cells(z + 1, 4) = cboReceiptType.Value & "- Serial# " & txtSerial.Value
        End With


Sheets("Log Sheet").Visible = True
Sheets("Log Sheet").Select

    With ActiveSheet

    .Unprotect Password:="miami"

        If PayoutFrm.cboReceiptType.Value = "VOID" Then Cells(, 28).Value = "VOID"
        If PayoutFrm.cboReceiptType.Value = "WINNER" Then Cells(, 28).Value = "PAID"
        If PayoutFrm.cboReceiptType.Value = "REFUND" Then Cells(, 28).Value = "REFUNDED"

    .Protect Password:="miami"
    .EnableSelection = xlNoSelection

    End With

Unload Me

Application.ScreenUpdating = True

End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Welcome to the Forum!

Can you please be more specific. What exactly is your "Lookup problem"?
 
Upvote 0
As you haven't given us much to go, it's difficult to help.
But as a starter
Code:
 Dim Rw as Long
With Sheets("Log Sheet").Range("A:A")
  Rw[COLOR=#ff0000][/COLOR] = .Find(What:=sFindIt, After:=.Cells(10, 1), LookIn:=xlValues, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, _
        SearchFormat:=False).Row
  
    
        If .Cells(Rw, 28).Value > 0 Then _
            MsgBox ("This bet has already been processed. Please select another bet"), vbCritical Or vbOKOnly
        If .Cells(Rw, 28).Value > 0 Then Exit Sub
        
        If PayoutFrm.cboReceiptType.Value = "WINNER" And .Cells(Rw, 22).Value <> "Winner" Then _
            MsgBox ("This bet is not a winning bet"), vbCritical Or vbOKOnly
        If PayoutFrm.cboReceiptType.Value = "WINNER" And .Cells(Rw, 22).Value <> "Winner" Then Exit Sub
  End With
see if this helps
 
Upvote 0
Im sorry for being not specific with the post

and your answer is what i was missing forgot to declare it and add it to the code...

Thabk you so much fluff.. i got my macro up and running
 
Upvote 0
As you haven't given us much to go, it's difficult to help.
But as a starter
Code:
 Dim Rw as Long
With Sheets("Log Sheet").Range("A:A")
  Rw[COLOR=#ff0000][/COLOR] = .Find(What:=sFindIt, After:=.Cells(10, 1), LookIn:=xlValues, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, _
        SearchFormat:=False).Row
  
    
        If .Cells(Rw, 28).Value > 0 Then _
            MsgBox ("This bet has already been processed. Please select another bet"), vbCritical Or vbOKOnly
        If .Cells(Rw, 28).Value > 0 Then Exit Sub
        
        If PayoutFrm.cboReceiptType.Value = "WINNER" And .Cells(Rw, 22).Value <> "Winner" Then _
            MsgBox ("This bet is not a winning bet"), vbCritical Or vbOKOnly
        If PayoutFrm.cboReceiptType.Value = "WINNER" And .Cells(Rw, 22).Value <> "Winner" Then Exit Sub
  End With
see if this helps

Thanks fluff .. this helped me to fix it
 
Upvote 0
Glad it's sorted & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,316
Members
452,634
Latest member
cpostell

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