+ Reply to Thread
Results 1 to 8 of 8

Populate username in next column after save

  1. #1
    Registered User
    Join Date
    04-16-2014
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    6

    Populate username in next column after save

    Hi, I'm new to VBA and trying to design a macro that populates a username in a neighboring column after a save. For example, a user populates a value in cell A1. When the worksheet is saved, the user's name appears in cell B1.

    Here's what I tried...

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If Sheets("Sheet1").Range("A1:A50").Value <> "" Then
    Sheets("Sheet1").Range("B1:B50").Value = Environ("username")
    End If
    End Sub

    Thanks for your help.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Populate username in next column after save

    Hi owings and welcome to the forum,

    Did your code work? What did you expect to happen that didn't?

    I'm not very good at English, but I didn't find a question mark in your post. Does that mean you don't have a question?

    It is always easier for us to understand your questions if you attach a sample file with the question.
    Click on "Go Advanced" below the message area and then on the Paper Clip Icon to attach a file.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Populate username in next column after save

    Please use code tags when posting. Try:

    Please Login or Register  to view this content.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Populate username in next column after save

    or
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-16-2014
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Populate username in next column after save

    Thank you John & Marvin.

    John, I used your code and it works like a charm... with one caveat (because i did not clearly explain the intended functionality in my previous post)...

    the code overwrites everything in the column... this is a shared workbook... so for example, if a user modifies cell A1 and saves, then another user modifies cell A2 and saves, both B1 and B2 will reflect the 2nd user... how do i get the workbook to keep the first user's name in B1?

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Populate username in next column after save

    Try change this line:

    If Cells(RowCtr, "A") <> "" Then Cells(RowCtr, "B") = Environ("username")

    to

    If Cells(RowCtr, "A") <> "" AND Cells(RowCtr, "B") = "" Then Cells(RowCtr, "B") = Environ("username")

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Populate username in next column after save

    Maybe:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    04-16-2014
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Populate username in next column after save

    Success! Thank you both for sharing your knowledge and helping me with this question!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. unlocking with username and autolocking when save
    By angel2903 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-13-2014, 10:50 AM
  2. [SOLVED] Username and Password Form - Show Username in Sheet
    By ryan180 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-24-2013, 07:06 PM
  3. [SOLVED] how to add username to file name on save
    By tinkerbelle in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-20-2012, 03:53 PM
  4. Save to a path that requires username and password
    By brl8 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-30-2011, 06:00 PM
  5. [SOLVED] How do I populate a cell with the NT Logon username?
    By Mike in forum Excel General
    Replies: 1
    Last Post: 06-03-2005, 03:05 AM

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