+ Reply to Thread
Results 1 to 7 of 7

Recording contents of cells into multiple columns

Hybrid View

  1. #1
    Registered User
    Join Date
    04-16-2010
    Location
    london,england
    MS-Off Ver
    Excel 2007
    Posts
    8

    Recording contents of cells into multiple columns

    Hi all, I was given this answer by Tony H to my question about recording the contents of a cell which is linked to an IP address every 15 minutes into a column and it works. I would now like to record 12 different IP addresses into columns for Temperature and Humidity of Data halls but I'm stuck. Can anyone help please.
    Code:
    Sub GetData()
    Dim rng As Range
    Dim i As Long
    Dim dte As Date
    Dim dteNext As Date

    dte = Now
    Set rng = activesheet.Range("E1")
    For i = 1 To 3 'change this to number of time to loop
    ThisWorkbook.RefreshAll
    DoEvents
    Set rng = rng.Offset(1)
    rng = Now
    rng.Offset(, 1) = activesheet.Range("B3")
    dteNext = dte + TimeSerial(Hour:=0, Minute:=1 * i, Second:=0) 'change this value to number of minutes
    Application.Wait dteNext
    Next
    MsgBox "done"
    End Sub
    Code:
    Last edited by pillory; 04-24-2010 at 04:51 AM.

  2. #2
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Recording contents of cells into multiple columns

    A note on Forum Rules: when posting code you must use code tage. That is you start your code with (but without the space) [co de] and end with [/co de]

    I presume you have set up the links as before. I have added in a couple of example lines. It stores all the values in adjacent columns

    Sub GetData()
        Dim rng As Range
        Dim i As Long
        Dim dte As Date
        Dim dteNext As Date
        
        dte = Now
        Set rng = ActiveSheet.Range("E1")
        For i = 1 To 3 'change this to number of time to loop
            ThisWorkbook.RefreshAll
            DoEvents
            Set rng = rng.Offset(1)
            rng = Now
            
            ''
            ''change this block to the actually addresses you need
            ''
            rng.Offset(, 1) = ActiveSheet.Range("B3")   '1st piece of data
            rng.Offset(, 2) = ActiveSheet.Range("C5")   '2nd piece of data
            rng.Offset(, 3) = ActiveSheet.Range("B12")  '3rd piece of data
            
            dteNext = dte + TimeSerial(Hour:=0, Minute:=1 * i, Second:=0) 'change this value to number of minutes
            Application.Wait dteNext
        Next
        MsgBox "done"
    End Sub


    click on the * Add Reputation if this was useful or entertaining.

  3. #3
    Registered User
    Join Date
    04-16-2010
    Location
    london,england
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Recording contents of cells into multiple columns

    tony h. Thanks for your help and the solution you gave me seems to work returning all 12 temperature and humidity readings from the IP addresses of the building management system into adjacent boxes that I can then colour code for in or out of limits, but the Excel sheet seems to lock up so that as soon as I run the Macro you gave me the numbers returned by the IP addresses freeze and I get row after row of the same readings instead of dynamic readings until the Macro has completed. Do you have any Ideas whats causing this and how to overcome it. Thanks.

  4. #4
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Recording contents of cells into multiple columns

    deleted: see my next post
    Last edited by tony h; 04-19-2010 at 06:59 AM.

  5. #5
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Recording contents of cells into multiple columns

    Ok, I have had a bit of a look and I think the code below should do the job.
    What you do need to do is make sure that the connection is set with the "enable background refresh" to "off" ie un-ticked.
    : on the data tab ... go to connections ... existing connections and pick properties

    Sub GetData2()
        Dim rng As Range
        Dim i As Long
        Dim dte As Date
        Dim dteNext As Date
        Dim iMax As Long
        Dim wkb As Workbook
        
        Set wkb = ThisWorkbook
        dte = Now
        Set rng = ActiveSheet.Range("M1")
        iMax = 3 'change this to number of time to loop
        For i = 1 To iMax
            wkb.RefreshAll
            
            
            rng = Now
            
            ''
            ''change this block to the actually addresses you need
            ''
            rng.Offset(, 1) = ActiveSheet.Range("B3")   '1st piece of data
            rng.Offset(, 2) = ActiveSheet.Range("B15")  '2nd piece of data
            rng.Offset(, 3) = ActiveSheet.Range("B16")  '3rd piece of data
            
            Set rng = rng.Offset(1)
            dteNext = dte + TimeSerial(Hour:=0, Minute:=1 * i, Second:=0) 'change this value to number of minutes
            'Application.Wait dteNext
            If i <> iMax Then Do: DoEvents: rng = Now: Loop Until Now >= dteNext
        Next
        MsgBox "done"
    End Sub

  6. #6
    Registered User
    Join Date
    04-16-2010
    Location
    london,england
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Recording contents of cells into multiple columns

    Thanks tony h for your huge effort to help. I am now off work until friday due to my shift pattern and so wont be able to try out your new code until then. As you can tell I am no programmer but will let you know how it goes over the weekend.

+ 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