Consulting

Results 1 to 7 of 7

Thread: Solved: Cell value capture

  1. #1
    VBAX Tutor
    Joined
    Sep 2008
    Posts
    213
    Location

    Solved: Cell value capture

    Id like to write a macro that will capture the value of a cell and post it to the next empty cell in sheet 2 every X minutes.

    I have RTD time server to provide me with the time in excel.

    (if theres a thread that covers this just a link would fine)

    Thanks

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Look at OnTime in VBA help, and also here
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Tutor
    Joined
    Sep 2008
    Posts
    213
    Location
    Ive been able to come up with the following ( a combination from my recent threads, thanks people). It does what it is expected to do, however I have come across another problem. The cell that it is supposed to be copying and pasting is actually a formula, so it actually copies and pastes the formula, not the value that I see in the cell. The value is what I actually want to record. how do I adjust the following to achieve this?
    [VBA]Public RunWhen As Double
    Public Const cRunIntervalSeconds = 60 'seconds
    Public Const cRunWhat = "TheSub" ' the name of the procedure to run
    Sub StartTimer()
    RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
    Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
    Schedule:=True
    End Sub
    Sub StopTimer()
    On Error Resume Next
    Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
    Schedule:=False
    End Sub
    Sub TheSub()
    ''''''''''''''''''''''''
    With Worksheets("Data")

    LastRow = .Range("A" & Rows.Count).End(xlUp).Row + 1
    Worksheets("Sheet1").Range("B20").Copy .Range("A" & LastRow)
    End With

    ''''''''''''''''''''''''
    StartTimer ' Reschedule the procedure
    End Sub
    [/VBA]

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]
    Worksheets("Sheet1").Range("B20").Copy
    .Range("A" & LastRow) .PasteSpecial Paste:=xlPasteValues
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Tutor
    Joined
    Sep 2008
    Posts
    213
    Location
    thanks again, I added it to the sub, but get an error saying 'object required' when I run it. It cut and pasted ok before the last change.
    [VBA]
    Sub TheSub()
    ''''''''''''''''''''''''
    With Worksheets("Data")

    LastRow = .Range("A" & Rows.Count).End(xlUp).Row + 1
    Worksheets("Sheet1").Range("B20").Copy.Range("A" & LastRow).PasteSpecial Paste:=xlPasteValues
    End With

    ''''''''''''''''''''''''
    StartTimer ' Reschedule the procedure
    End Sub[/VBA]

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    The Copy and Paste must be on two lines as posted
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    VBAX Tutor
    Joined
    Sep 2008
    Posts
    213
    Location
    Thanks, all seems to be working now.

Posting Permissions

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