+ Reply to Thread
Results 1 to 2 of 2

Lbound out of range

Hybrid View

  1. #1
    Registered User
    Join Date
    07-22-2013
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    7

    Lbound out of range

    I need some help here. I wrote some code to bring in some tag values from a third party piece of software. It works fine if I comment out the + i - 1, 1 part of the Lbound function, but says error 9 'Subscript out of range if I bring it back in.'

    What I'm trying to do is have only the last value of my tag value populate the cell and then update the value below with the new tag value, every second.

    Here's what I have:


    Dim Repeat As Boolean

    Sub PrepBook()
    Worksheets("Sheet1").OnSheetActivate = "Module1.AutoSheet"
    End Sub

    Sub AutoSheet()
    Repeat = False
    End Sub

    Sub GetDataButton() 'Get Data Button pressed
    If Repeat = False Then 'don't do anything if we're already getting data
    GetCurrentData
    End If
    End Sub

    Sub RepeatButton() 'Repeat Button pressed
    Repeat = True
    GetCurrentData
    End Sub

    Sub StopRepeatButton() 'Stop Repeat Button pressed
    Repeat = False
    End Sub

    Sub GetCurrentData()
    chan = DDEInitiate("RSLINX", "Mastermold_Single_Spiral3")
    If TypeName(chan) = "Error" Then
    Repeat = False
    MsgBox "Program Cannot Be Found"
    Else
    returndata = DDERequest(chan, "drive_amps")
    For i = LBound(returndata) To UBound(returndata)
    Worksheets("Sheet1").Cells(i + 1, 2).Value = returndata(LBound(returndata) + i - 1, 1) 'THIS IS THE LINE I'M GOING OUT OF RANGE ON'
    Next i
    returndata = DDERequest(chan, "takeup_amps")
    For i = LBound(returndata) To UBound(returndata)
    Worksheets("Sheet1").Cells(i + 2, 2).Value = returndata(LBound(returndata)) '+ i - 1, 1)
    Next i
    returndata = DDERequest(chan, "AIR_TEMPERATURE_SP2")
    For i = LBound(returndata) To UBound(returndata)
    Worksheets("Sheet1").Cells(i + 3, 2).Value = returndata(LBound(returndata)) '+ i - 1, 1)
    Next i
    DDETerminate chan
    Call Put_In_Place
    End If
    If Repeat Then Application.OnTime Now + TimeValue("00:00:01"), "GetCurrentData"
    End Sub

    Sub Put_In_Place()

    Worksheets("sheet1").Range("F" & _
    Worksheets("sheet1").Range("F" & _
    Rows.Count).End(xlUp).Offset(1, 0).Row & ":O" & _
    Worksheets("sheet1").Range("O" & _
    Rows.Count).End(xlUp).Offset(1, 0).Row) = _
    Application.WorksheetFunction.Transpose(Worksheets("sheet1").Range("B2:B14"))

    If IsNumeric(Worksheets("sheet1").Range("F" & _
    Worksheets("sheet1").Range("F" & _
    Rows.Count).End(xlUp).Row).Offset(-1, -1).Value) Then
    Worksheets("sheet1").Range("F" & _
    Worksheets("sheet1").Range("F" & _
    Rows.Count).End(xlUp).Row).Offset(, -1).Value = _
    Worksheets("sheet1").Range("F" & _
    Worksheets("sheet1").Range("F" & _
    Rows.Count).End(xlUp).Row).Offset(-1, -1).Value + 1
    Else
    Worksheets("sheet1").Range("F" & _
    Worksheets("sheet1").Range("F" & _
    Rows.Count).End(xlUp).Row).Offset(, -1).Value = 1
    End If
    End Sub

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Lbound out of range

    If you want the last value in array shouldn't you be using UBound, not LBound?

    PS Can you add code tags when posting code?
    If posting code please use code tags, see here.

+ 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] LBound/UBound Intersect together
    By janulikb in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-21-2013, 05:41 AM
  2. Ubound and Lbound
    By hommer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-21-2010, 11:58 AM
  3. [SOLVED] resize(Ubound, Lbound)
    By ina in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-01-2006, 10:00 AM
  4. Moving into a cell range using Offset and LBound
    By TISR in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-26-2006, 07:10 PM
  5. [SOLVED] Change LBound of array
    By R Avery in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-19-2005, 12:06 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