Search code examples
excelvbauserform

Trouble with Displaying a Current Date and Time when Logged In on a UserForm when it Initialize


I have the following code:

  Set FindRow = Hoja6.Range("B:B").Find(What:=User, LookIn:=xlValues, LookAT:=xlPart)

  Me.UserLog.Text = "Best Guy."
  Me.RecentUserLog.Value = FindRow.Offset(0, 1).Value
  Me.LastUserLog.Value = FindRow.Offset(1, 1).Value
  End If

If i hide the two last lines, it works fine. But if i keep it like this, its says

object variable or with object not set

I tried Hoja6.Select (sheet6.Select) but still does not work. The purpose is to show the current date and time and the last log. The user variable is public, and it works when i open the userform, but now i changed a bit the filters by user, and having trouble solving this.


Solution

  •     If User = "Guy" Then
    
            Me.UserLog.Text = "Guy."
            Set FindRow = Hoja6.Range("B:B").Find(What:="Big Guy", _
                                LookIn:=xlValues, LookAT:=xlPart)
    
            If FindRow Is Nothing Then
                Me.RecentUserLog.Value = ""
                Me.LastUserLog.Value = ""
            Else
                Me.RecentUserLog.Value = FindRow.Offset(1, 0)
                Me.LastUserLog.Value = FindRow.Offset(2, 0)
            End If
    
         End If