if *some condition* And Cell isEmpty problem

mysticmario

Active Member
Joined
Nov 10, 2021
Messages
323
Office Version
  1. 365
Platform
  1. Windows
Hi,
I am here sittign for 3 hours trying to figure out a way to code simple empty check for cell on top of password check and I cannot make it happen, Can you please help me with this code? I am still learning VBA and sometimes computer logic doesnt add up with my lgoic and stuff dont work :D

VBA Code:
Private Sub IMusinIN_Click()
  ivanpin = InputBox("Enter PIN:", Verification)
  If ivanpin = 1234 Then
  Dim sh As Worksheet
    Set sh = ThisWorkbook.Sheets("Currently logged in")

    sh.Range("C9").Value = Now
    
loginvar = MsgBox("Logged in", vbOKOnly, "Login")
Unload Me
Else
MsgBox "Wrong PIN!", vbOKOnly + vbExclamation, "Error"
End If
        
End Sub
I wanted to add: And isEmpty(ThisWorkbook.Sheets("Currently logged in").Range("C9").Value = True
to IF statement
and ElseIf isEmpty(ThisWorkbook.Sheets("Currently logged in").Range("C9").Value = False Then msgbox popup
But it doesn't work. I tried multiple different options and code combinations nothing seems to work It's late and I'm exhausted, maybe someone can help me out?
Thank You in advance good people :)
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Not sure about this, but try ...

VBA Code:
Private Sub IMusinIN_Click()
    Dim ivanpin As Variant
    
    Dim Rng As Range
    Set Rng = ThisWorkbook.Sheets("Currently logged in").Range("C9")
    
    If IsEmpty(Rng.Value) Then
        ivanpin = InputBox("Enter PIN:", "Verification")
        If ivanpin = 1234 Then
            Rng.Value = Now
            MsgBox "Logged in", vbOKOnly, "Login"
            Unload Me
        Else
            MsgBox "Wrong PIN!", vbOKOnly + vbExclamation, "Error"
        End If
    End If
End Sub
 
Upvote 0
Solution
It somewhat works, not entirely what I needed but it blocks the possibility to reEnter which was my main goal.
Thanks
 
Upvote 0
I have so many more questions, VBA is not that easy after and I am trying to create entire managing system for my office :D
 
Upvote 0
Feel free to start a new thread with one of your many more questions, after all that's what this forum is for.
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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