+ Reply to Thread
Results 1 to 7 of 7

UserName Changes to Current User When Changes Are Made To Any Data Already Entered

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-14-2012
    Location
    Tucson, Arizona, USA
    MS-Off Ver
    Office 2010
    Posts
    105

    UserName Changes to Current User When Changes Are Made To Any Data Already Entered

    I've encountered a problem recently where, when the data is changed in a cell already containing data, all the automatically entered UserNames in the spreadsheet are changed to the current user. This causes a problem when we need to know when the data was entered and by WHOM.

    I have been using the following macro
    Function NetworkUserName() As String
       NetworkUserName = Environ("Username")
    End Function
    Followed by the following formula entered into the respective cell
    =IF(B5>0,NetworkUserName(),"")
    Obviously the reference cell, B5, changes as needed as you move down the spreadsheet

    The way I had originally understood it, once the data was entered or changed in the referenced cell, only then would the UserName in the cell with the formula change. I need help figuring out how to stop this from happening unintentionally.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: UserName Changes to Current User When Changes Are Made To Any Data Already Entered

    It's a formula, just like =NOW(). It's not volatile, but if B5 changes from any value to a positive value, the function will return the current username to each cell in which it appears.

    If you want the value to remain static, your code must enter a value (not a formula) in the cell.
    Last edited by shg; 11-29-2012 at 12:24 PM.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    09-14-2012
    Location
    Tucson, Arizona, USA
    MS-Off Ver
    Office 2010
    Posts
    105

    Re: UserName Changes to Current User When Changes Are Made To Any Data Already Entered

    I'm using a UserForm to enter data in each row starting with B5 to P5 and working its way to row 376.

    UserForm coding
    Private Sub cmdAdd_Click()
    Dim iRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Thermals")
    
    'find  first empty row in database
    iRow = Worksheets("Thermals").Range("P376").End(xlUp).Row + 1
     
    'check for a date
    If Trim(Me.cboDate.Value) = "" Then
      Me.cboDate.SetFocus
      MsgBox "Please enter the Date and Time then the Temperatures"
      Exit Sub
    End If
    
    'copy the data to the database
    With ws
      .Cells(iRow, 2).Value = Me.cboDate.Value
      .Cells(iRow, 3).Value = Me.cboTime.Value
      .Cells(iRow, 4).Value = Me.txtChWtrSup.Value
      .Cells(iRow, 5).Value = Me.txtChWtrRet.Value
      .Cells(iRow, 6).Value = Me.txtConWtrRet.Value
      .Cells(iRow, 7).Value = Me.txtConWtrSup.Value
      .Cells(iRow, 8).Value = Me.txtHeatWtrSup.Value
      .Cells(iRow, 9).Value = Me.txtHeatWtrRet.Value
      .Cells(iRow, 10).Value = Me.txtSluHeatSup.Value
      .Cells(iRow, 11).Value = Me.txtSluHeatRet.Value
      .Cells(iRow, 12).Value = Me.txtWstHeatSup.Value
      .Cells(iRow, 13).Value = Me.txtWstHeatRet.Value
      .Cells(iRow, 14).Value = Me.txtDomHWtrRet.Value
      .Cells(iRow, 15).Value = Me.txtDomColdWtr.Value
      .Cells(iRow, 16).Value = Me.txtDomHWtrSup.Value
    End With
    
    'clear the data
    Me.cboDate.Value = ""
    Me.cboTime.Value = ""
    Me.txtChWtrSup.Value = ""
    Me.txtChWtrRet.Value = ""
    Me.txtConWtrRet.Value = ""
    Me.txtConWtrSup.Value = ""
    Me.txtHeatWtrSup.Value = ""
    Me.txtHeatWtrRet.Value = ""
    Me.txtSluHeatSup.Value = ""
    Me.txtSluHeatRet.Value = ""
    Me.txtWstHeatSup.Value = ""
    Me.txtWstHeatRet.Value = ""
    Me.txtDomHWtrRet.Value = ""
    Me.txtDomColdWtr.Value = ""
    Me.txtDomHWtrSup.Value = ""
    Me.cboDate.SetFocus
    
    End Sub
    
    Private Sub UserForm_Initialize()
    'Populates the Date & Time Comboboxes
      Dim rngDate As Range
      Dim rngTime As Range
      Dim ws As Worksheet
      Set ws = Worksheets("DateTime")
      For Each rngDate In ws.Range("DateList")
        Me.cboDate.AddItem rngDate.Text
      Next rngDate
      Set ws = Worksheets("DateTime")
      For Each rngTime In ws.Range("TimeList")
        Me.cboTime.AddItem rngTime.Text
      Next rngTime
        
    End Sub
    
    Private Sub cmdClose_Click()
      Sheets("Thermals").Select
      ActiveSheet.Protect Password:="password", DrawingObjects:=True, Contents:=True, Scenarios:=True
      Sheets("Main").Select
      Unload Me
    
    End Sub
    
    Private Sub UserForm_QueryClose(Cancel As Integer, _
      CloseMode As Integer)
      If CloseMode = vbFormControlMenu Then
        Cancel = True
        MsgBox "Please use the 'Close' button!"
      End If
    End Sub
    How would I alter this to automatically enter the static UserName then?

  4. #4
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: UserName Changes to Current User When Changes Are Made To Any Data Already Entered

    When a referenced cell value changes, all the formulas are automatically updated with current results. You can stop this automatic calc functionality from excel options or paste only values in earlier cells.

  5. #5
    Forum Contributor
    Join Date
    09-14-2012
    Location
    Tucson, Arizona, USA
    MS-Off Ver
    Office 2010
    Posts
    105

    Re: UserName Changes to Current User When Changes Are Made To Any Data Already Entered

    My apologies if I don't fully understand where you're pointing me. As I currently understand it, the coding I'm using determines who the current user is and the formula in the cell shows that information (the value) in its current location (the formulas cell wherever it may be, say Q5) when information has been entered into the referenced cell (B5 in this case). This makes the cell (Q5) data volatile, correct? How do I go about making it static? The information changes depending upon whomever enters data into the spreadsheet and the user listed in row 5 may not be the same as the user entering data in row 6 and so on down the line for up to 372 rows, literally. I don't mean to be a pain asking this or sound like a smartalec.

  6. #6
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: UserName Changes to Current User When Changes Are Made To Any Data Already Entered

    After Cells(irow,16) value you can add below to print current user name in the next cell.
    .Cells(iRow, 17).Value = Environ("Username")

  7. #7
    Forum Contributor
    Join Date
    09-14-2012
    Location
    Tucson, Arizona, USA
    MS-Off Ver
    Office 2010
    Posts
    105

    Re: UserName Changes to Current User When Changes Are Made To Any Data Already Entered

    Know something, I do a REAL GOOD impression of Homer Simpson - "DOH!!!". I was looking so hard for a "full macro" that it didn't occur to me to insert it like that into the already existing code. I wasn't seeing the forest for the trees so to speak.
    Last edited by LoneWolf3574; 11-27-2012 at 05:14 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1