+ Reply to Thread
Results 1 to 14 of 14

Todays Date VBA for column

Hybrid View

  1. #1
    Registered User
    Join Date
    10-18-2016
    Location
    Frankfurt, Germany
    MS-Off Ver
    2010
    Posts
    82

    Exclamation Todays Date VBA for column

    I need for every column that has "Date" as a column header, the cells to populate today's date when the adjacent 3 columns are filled in (Weekday, Logged in, Status).

    This will be worked on daily, so I don't want the previous days date to change to today's - is this possible through vba?
    Attached Files Attached Files

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Todays Date VBA for column

    Try this in your sheet 1 module:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim H As String, r As Long, c As Long, n As Long
    c = Target.Column: r = Target.Row: H = Cells(3, c)
    If InStr(1, H, "day") Then n = -1
    If InStr(1, H, "gg") Then n = -2
    If InStr(1, H, "tat") Then n = -3
    Application.EnableEvents = False
    If Cells(r, c + n) = "" Then Cells(r, c + n) = Date
    Application.EnableEvents = True
    End Sub
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    10-18-2016
    Location
    Frankfurt, Germany
    MS-Off Ver
    2010
    Posts
    82

    Re: Todays Date VBA for column

    Quote Originally Posted by xladept View Post
    Try this in your sheet 1 module:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim H As String, r As Long, c As Long, n As Long
    c = Target.Column: r = Target.Row: H = Cells(3, c)
    If InStr(1, H, "day") Then n = -1
    If InStr(1, H, "gg") Then n = -2
    If InStr(1, H, "tat") Then n = -3
    Application.EnableEvents = False
    If Cells(r, c + n) = "" Then Cells(r, c + n) = Date
    Application.EnableEvents = True
    End Sub
    Wow, this is amazing. Is it possible to tweak it slightly and update with today's date only if "Logged in" and "Status" columns are filled in?

    I would like to have a shift under the weekday already inputted in advance, so I don't want the date to populate if the weekday column has data...

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Todays Date VBA for column

    Sure Here:

    Sub Manny(): Dim H As String, r As Long, c As Long, n As Long, T As Range
    Set T = ActiveCell: c = T.column: r = T.Row: H = Cells(3, c)
    'If InStr(1, H, "day") Then n = -1
    If InStr(1, H, "gg") Then n = -2
    If InStr(1, H, "tat") Then n = -3
    If Cells(r, c + n) = "" Then Cells(r, c + n) = Date
    End Sub
    And, thanks for the rep!

  5. #5
    Registered User
    Join Date
    10-18-2016
    Location
    Frankfurt, Germany
    MS-Off Ver
    2010
    Posts
    82

    Re: Todays Date VBA for column

    Quote Originally Posted by xladept View Post
    Sure Here:

    Sub Manny(): Dim H As String, r As Long, c As Long, n As Long, T As Range
    Set T = ActiveCell: c = T.column: r = T.Row: H = Cells(3, c)
    'If InStr(1, H, "day") Then n = -1
    If InStr(1, H, "gg") Then n = -2
    If InStr(1, H, "tat") Then n = -3
    If Cells(r, c + n) = "" Then Cells(r, c + n) = Date
    End Sub
    And, thanks for the rep!
    Welcome!

    That isn't populating any dates when I enter data into "logged in" and "status" - Am i doing something wrong?

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Todays Date VBA for column

    On second thought, since it's event code and nothing happens run this code:

    Sub Enable()
    Application.EnableEvents=True
    End Sub

  7. #7
    Registered User
    Join Date
    10-18-2016
    Location
    Frankfurt, Germany
    MS-Off Ver
    2010
    Posts
    82

    Re: Todays Date VBA for column

    Quote Originally Posted by xladept View Post
    On second thought, since it's event code and nothing happens run this code:

    Sub Enable()
    Application.EnableEvents=True
    End Sub
    I don't know what it is, but placing the script you wrote into vba doesn't populate today's date under the "Date" column when something is entered in "logged in" and "status" - Are you able to attach a working sample?

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Todays Date VBA for column

    It's working for me, is there a different sample?

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,343

    Re: Todays Date VBA for column

    Give this a try.
    Attached Files Attached Files
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  10. #10
    Registered User
    Join Date
    10-18-2016
    Location
    Frankfurt, Germany
    MS-Off Ver
    2010
    Posts
    82

    Re: Todays Date VBA for column

    Quote Originally Posted by bakerman2 View Post
    Give this a try.
    That works great. Rep added.


    - Are you able to help with this formula I am trying to get right? I want the Time Card tab columns Due in, Login, Status to display the due in, login and status from the Late tab - By agent name and By Date. This is so I can apply it into a Pivot table
    Attached Files Attached Files

  11. #11
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Todays Date VBA for column

    Hi manny,

    Here's the working sample:
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    10-18-2016
    Location
    Frankfurt, Germany
    MS-Off Ver
    2010
    Posts
    82

    Re: Todays Date VBA for column

    Quote Originally Posted by xladept View Post
    Hi manny,

    Here's the working sample:
    I entered the same script, but it didn't work for me for whatever reason, that's great Xladept.

    Are you, bakerman, or anyone else reading able to help with the 10th post in the thread RE: Timecard ? I know it's not vba, more just a formula I can't seem to get

  13. #13
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,343

    Re: Todays Date VBA for column

    Manny, I would strongly advice to re-design your late Sheet into a 7 column data sheet like Name|Team manager|Day|Date|Due|Logged|Status.
    This way you open up a lot more possibilities like AutoFilter, AdvancedFilter and you could get your PivotTable Data straight from your Late Sheet.
    Thatway you wouldn't have to resort to an in between solution like you are trying now.

  14. #14
    Registered User
    Join Date
    10-18-2016
    Location
    Frankfurt, Germany
    MS-Off Ver
    2010
    Posts
    82

    Re: Todays Date VBA for column

    Quote Originally Posted by bakerman2 View Post
    Manny, I would strongly advice to re-design your late Sheet into a 7 column data sheet like Name|Team manager|Day|Date|Due|Logged|Status.
    This way you open up a lot more possibilities like AutoFilter, AdvancedFilter and you could get your PivotTable Data straight from your Late Sheet.
    Thatway you wouldn't have to resort to an in between solution like you are trying now.
    Thanks Bakerman, I realized this (and kept the vba sample in my back pocket). The Timecard attachment I posted includes the idea you pitched, but I am having difficulty with the formula pulling Due|Login|Status from the Late tab according to the agent name and the date
    Attached Files Attached Files

+ 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. Replies: 3
    Last Post: 04-08-2016, 09:11 AM
  2. Autohide Columns that are < todays date and > todays date by 2 & 7 days
    By Dropfiddy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-28-2015, 03:51 AM
  3. I want to find the difference between todays date and the Date in the 10 column in VBA
    By erickmcburger in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-23-2015, 07:29 AM
  4. [SOLVED] getting total from column if todays date is equal to or greater than date column
    By peterjb44 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-11-2013, 07:43 PM
  5. Auto Fill Todays Date In Column K in Last Value Found in Column A
    By trevor2524 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-18-2013, 02:42 PM
  6. [SOLVED] Create new column with todays date and jump to column
    By ping8781 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-19-2010, 06:53 AM
  7. Using VB to find a range based on todays date and todays date +30
    By Steve_al in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-13-2009, 09:31 AM

Tags for this Thread

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