+ Reply to Thread
Results 1 to 5 of 5

Need help on taking a data from a cell & keep pasting in subsequent rows in a column?

  1. #1
    Registered User
    Join Date
    07-15-2017
    Location
    India
    MS-Off Ver
    MS Office 2013
    Posts
    11

    Unhappy Need help on taking a data from a cell & keep pasting in subsequent rows in a column?

    I want to sample a variable data in a cell say C3 & to display that data after every 1 second (Means sampling rate is 1 Hz) into the rows (one after one) in a column say D. To explain, after starting up the Macro, value of C3 should display in D1 and after 1 second updated value of C3 should display in D2 and so on for 900 times because I want this sampling for 15 minutes (15*60=900 seconds) and want to know average (of course variable) of those 900 cells (filled as well as empty) from D1 to D900.
    to achieve this I have used following code

    " Option Explicit
    Public dTime As Date

    Sub ValueStore()
    Dim dTime As Date
    Range("D" & Cells(Rows.Count).Row).End().Offset(1, 0).Value = Range("C3").Value
    Call StartTimer
    End Sub


    Sub StartTimer()
    dTime = Now + TimeValue("00:00:01")
    Application.OnTime dTime, "ValueStore", Schedule:=True
    End Sub

    Sub StopTimer()
    On Error Resume Next
    Application.OnTime dTime, "ValueStore", Schedule:=False
    End Sub "

    Two separate Command Buttons are created for StartTimer() & StopTimer().

    Now 1st problem is Value starts displaying from Cell D2 but that is not an issue for me. The main issue is above code gives only 63 sampled values means from D2 to D64 & after that no data displays in D65 and subsequent cells but Value of D3 keeps updating. I could not understand why D65 & subsequent cells are not displaying updated C3 value. There seems nothing that put limit at 63 values & why value of D3 keeps updating? Please help me out.

    Additional Functionality Required:
    Now, I want to display only 900 values after that (15 minutes) all cells from D2 to D64 should be blank and whole process of sampling should start from D2 to D901 so that I can watch variable Average of next one by one 900 values also. Can somebody provide me additional code for this?

    I use MS Office 2013.

    Sincere thanks in advance.
    Last edited by ansheng; 01-10-2019 at 12:53 PM.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Need help on taking a data from a cell & keep pasting in subsequent rows in a column?

    try this
    Please Login or Register  to view this content.
    Last edited by JLGWhiz; 01-10-2019 at 02:00 PM.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Registered User
    Join Date
    07-15-2017
    Location
    India
    MS-Off Ver
    MS Office 2013
    Posts
    11

    Re: Need help on taking a data from a cell & keep pasting in subsequent rows in a column?

    Thank you very much JLGWhiz.
    Your code works perfectly.
    To achieve additional functionality mentioned in thread I have modified your Sub t & added one more Sub Repeat. Now new code is

    " Sub t()

    Dim i As Long, s As Variant
    For i = 1 To 900
    Range("D" & i) = Range("C3").Value
    s = Timer + 1
    Do While Timer < s
    DoEvents
    Loop
    Next
    Range("D1:D900").ClearContents

    End Sub


    Sub Repeat()
    Dim i As Long
    For i = 1 To 4
    Call t
    Next
    End Sub "

    I am adding some more functionalities like creating a disable button to stop whole process etc.

    Once again a sincere thanks to JLGWhiz!
    Last edited by ansheng; 01-11-2019 at 10:29 AM.

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Need help on taking a data from a cell & keep pasting in subsequent rows in a column?

    You're welcome, but you need to be putting code tags on the code when you post it. To do that easily, use the mouse pointer to highlight (select) the code, then click the pound symbol (#) in the tool bar. The code tags will be applied to your code and it will retain formatting when you click the 'Post Quick Reply' button.
    Regards, JLG

  5. #5
    Registered User
    Join Date
    07-15-2017
    Location
    India
    MS-Off Ver
    MS Office 2013
    Posts
    11

    Re: Need help on taking a data from a cell & keep pasting in subsequent rows in a column?

    JLGWhiz, I have tried this code to sample variable value of cell D1 at every second. Code runs perfectly upto 23:59:59 hrs but after that Timer stops. Sampling of cell D1 needs to be done 24x7. I have checked Timer's value reaches to 86398. I tried to reset Timer but VBA gives error that Read Only property can not be changed.
    I tried s = Now + TimeValue("00:00:01") also instead of Timer function but that does not samples value of D1 exactly at 1 second interval. So, I want to use Timer.
    For that I want to know how to reset Timer, if possible?
    Or any other way so that sampling of values of D1 keeps continue after 23:59:59 hrs.

    Thanks.

+ 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: 2
    Last Post: 03-28-2018, 11:10 PM
  2. [SOLVED] using indirect to get same column, subsequent rows from different sheet
    By jrtaylor in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 02-07-2018, 10:42 AM
  3. VBA- Relative Cell Reference taking one value and pasting to all cells in a column
    By mrblue1123 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-20-2013, 09:49 AM
  4. Need help moving multiple lines of data in single cell to unique subsequent rows
    By brettmburns in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-21-2012, 03:04 PM
  5. macro for entering formula and subsequent pasting of blank column
    By ElisaB in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-29-2011, 11:21 AM
  6. update the subsequent rows at each change in other column
    By pavan.dhoke in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 03-28-2011, 05:49 AM
  7. taking data at end of column and sending it to cell in another workbook
    By gdecat in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-14-2005, 02:22 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