+ Reply to Thread
Results 1 to 2 of 2

Updating excel range with dynamic price data

Hybrid View

  1. #1
    Registered User
    Join Date
    12-03-2008
    Location
    MELBOURNE
    Posts
    5

    Smile Updating excel range with dynamic price data

    Hi

    I have a function that gets me the last bid price of a stock and displays it in a single worksheet cell. It's inside some timer code so it gets the price each second.

    But what if I want to show the last 10 bid prices in
    the range("a1:a10")
    , and when the 11th came in all the values would move up a row, so I see just the last 10.

    I was thinking something like the following - but obviously I can't get it working :=(

    m_BidPrice = myArray(i) 'put the bid into the array
    i = i+1 
    If i > 10 then somehow move all the values up 1 in myArray()
    select the sheet
    range("a1:a10")=myArray
    Any suggestions would be great - thanks
    Last edited by Matt1234au; 05-06-2009 at 11:33 PM.

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Updating excel range with dynamic price data

    You can try to use this code:
    Private Sub Macro1()
       Dim myRow As Long, lastRow As Long
       
       lastRow = Cells(Rows.Count, "a").End(xlUp).Row
       
       If lastRow > 9 Then
          For r = 2 To 10
             Cells(r - 1, "a") = Cells(r, "a")
          Next r
          myRow = 10
       Else
          If Cells(1, "a") = "" Then
             myRow = 1
          Else
             myRow = lastRow + 1
          End If
       End If
       Cells(myRow, "a") = bid_price 'new entry
    End Sub
    Regards,
    Antonio
    Last edited by antoka05; 05-06-2009 at 09:21 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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