+ Reply to Thread
Results 1 to 7 of 7

Capture value from a dynamic cell at a specific Hour and populate a column

Hybrid View

  1. #1
    Registered User
    Join Date
    01-02-2018
    Location
    London
    MS-Off Ver
    2010
    Posts
    54

    Capture value from a dynamic cell at a specific Hour and populate a column

    Hi,

    Cell A1 values changes dynamically throughout the day till say 1550 hours.

    I am looking to capture value from a dynamic cell (A1) at a specific hour say at 1600 hours.

    The captured value will be saved in a column (B) everyday with date (column A) starting from say Row10.

    Not able to attach a sample sheet as the attachment window is not working. A picture is attached instead.

    Thanks,


    Sample 1.jpg

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,962

    Re: Capture value from a dynamic cell at a specific Hour and populate a column

    The attach file button doesn't work - click "Go Advanced" to the lower right of the edit window, then use the "Manage attachments" option.

    Save your file as a macro-enabled .xlsm and change "SheetName" in two places in the code to the actual sheet name.

    With this in a regular code module:

    Option Explicit
    Dim NextTime As Date
    
    Sub ScheduleRun()
        'Schedule for 1600
        NextTime = Date + 1600 / 2400
        Application.OnTime NextTime, "RunMe"
    End Sub
    
    Sub RunMe()
        Dim shW As Worksheet
        Set shW = ThisWorkbook.Worksheets("SheetName")
        
        shW.Cells(shW.Rows.Count, "A").End(xlUp)(2).Value = Date
        shW.Cells(shW.Rows.Count, "A").End(xlUp)(1, 2).Value = shW.Range("A1").Value
    End Sub
    
    Sub StopMe()
        'Un-schedule for today...
        Application.OnTime NextTime, "RunMe", Schedule:=False
    End Sub
    And this in the codemodule of the ThisWorkbook object:

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
        Dim shW As Worksheet
        Set shW = ThisWorkbook.Worksheets("SheetName")
        
        If shW.Cells(shW.Rows.Count, "A").End(xlUp).Value = Date Then Exit Sub
        StopMe
        RunMe
    End Sub
    
    Private Sub Workbook_Open()
        ScheduleRun
    End Sub
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    01-02-2018
    Location
    London
    MS-Off Ver
    2010
    Posts
    54

    Re: Capture value from a dynamic cell at a specific Hour and populate a column

    Bernie Deitrick,

    Thanks.

    Attached is the Test.xlsm file with the codes.

    It is not working.

    I have changed the time to 1200 hours.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,962

    Re: Capture value from a dynamic cell at a specific Hour and populate a column

    You put the event code into a standard codemodule rather than the Thisworkbook object's codemodule: I have attached a working version with one change that I made to make testing easier: instead of 1200/2400 I use TimeSerial(12,0,0) (if you wanted to run at 11:47 AM, you would not use 1147/2400: TimeSerial(11,47,0) will allow you to choose that as the exact time.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    01-02-2018
    Location
    London
    MS-Off Ver
    2010
    Posts
    54

    Re: Capture value from a dynamic cell at a specific Hour and populate a column

    hi,

    It is working. Thanks for the effort and time.

    Issues I noticed:
    Right now it saves the required data when we close and reopen the file. It does not do it at the designated time when the workbook is open.
    Also reopening the workbook multiple times on same date it shows multiple entries of the same date.

    Though my basic requirement has been met it would be nice if above issues are addressed.

    Thanks again,

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,962

    Re: Capture value from a dynamic cell at a specific Hour and populate a column

    Change RunMe to this to address the multiple saves:
    Sub RunMe()
        Dim shW As Worksheet
        Set shW = ThisWorkbook.Worksheets("SheetName")
        If shW.Cells(shW.Rows.Count, "A").End(xlUp).Value = Date Then Exit Sub
        shW.Cells(shW.Rows.Count, "A").End(xlUp)(2).Value = Date
        shW.Cells(shW.Rows.Count, "A").End(xlUp)(1, 2).Value = shW.Range("A1").Value
    End Sub

    The timing / schedule works for me: are you opening the workbook once in the morning and closing it after the time that you want to store the data?

+ 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. [SOLVED] How to capture a max value in a dynamic cell
    By toughy1 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-08-2019, 04:38 PM
  2. [SOLVED] Populate a specific cell with column heading name.
    By redoscar in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-10-2017, 04:11 PM
  3. Replies: 1
    Last Post: 02-12-2015, 01:48 PM
  4. Replies: 5
    Last Post: 09-26-2014, 10:51 AM
  5. Replies: 4
    Last Post: 04-29-2014, 10:04 AM
  6. Replies: 3
    Last Post: 01-06-2011, 01:16 AM
  7. capture unique values from 1 column and populate the result into another column
    By teachMeExcel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-28-2009, 05:21 PM

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