Consulting

Results 1 to 4 of 4

Thread: increment a cell reference

  1. #1
    VBAX Newbie
    Joined
    Jul 2017
    Posts
    4
    Location

    increment a cell reference

    Im new to VBA and just starting using it this morning.
    I have this vba code in a workbook, lets call it "info", that saves the username and timestamp when a person opens it to a workbook called "counter". So with this code, it saves the username to A2 and the timestamp to B2 in the "counter" workbook. I got part of it working fine. I want the cells it saves the information to, to increment by one everytime someone opens the workbook. So when its opened again, it saves the username in A3 and timestamp in B3....then to A4 & B4.....and so on. Here is the current code:

    Private Sub Workbook_Open()
    ['C:\Users\RTL\Documents\[Counter.xlsx]Sheet1'!A2] = Application.UserName
    ['C:\Users\RTL\Documents\[Counter.xlsx]Sheet1'!B2] = DateTime.Now
    End Sub

    I've tried creating variables and strings but could not get it to work.

    Can you help me with this?

    Also, currently I have to keep the counters workbook open for it to work. Is there a way to do it where I can leave the counter workbook closed?
    Last edited by rtlane; 07-12-2017 at 11:48 AM.

  2. #2
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    613
    Location
    .

    Paste in ThisWorkbook module :

    Private Sub Workbook_Open()
    'Paste this macro into the ThisWorkbook module
    Dim LR As Long
    With Sheets("Log")
        LR = Range("A" & Rows.Count).End(xlUp).Row
        Range("A" & LR + 1).Value = Environ("username")
        Range("B" & LR + 1).Value = Format(Now, "m/d/yy hh:mm:ss")
    End With
    End Sub
    I prefer to format column B as :

    CUSTOM

    "m/d/yyyy h:mm:ss"

  3. #3
    VBAX Newbie
    Joined
    Jul 2017
    Posts
    4
    Location
    Thank you, this worked!

  4. #4
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    613
    Location
    .
    You are welcome. Glad to help.

Posting Permissions

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