Results 1 to 4 of 4

For loop exiting prematurely

Threaded View

whburling For loop exiting prematurely 05-29-2017, 03:51 PM
MarvinP Re: a "for loop" is exiting... 05-29-2017, 03:59 PM
whburling Re: a "for loop" is exiting... 05-29-2017, 04:11 PM
whburling Re: a "for loop" is exiting... 05-29-2017, 04:01 PM
  1. #1
    Forum Contributor
    Join Date
    02-13-2016
    Location
    CT USA
    MS-Off Ver
    office 365 subscription
    Posts
    180

    For loop exiting prematurely

    A “for loop” is exiting prematurely.

    You can find the loop that is giving me troubles at the line(about half way down):
    “For Row = DataRow To Ptr2FDc.count + DataRow”

    The debugger gets as far as just before executing the line:
    .Cells(Row, ElevationIDColumn).value = Ptr2FDc(Index).ID

    The code exits immediately (without executing the above line of code) to the end of the workbook.

    I checked the “for” variables. DataRow IS 2 and Ptr2FDc.count IS 20
    Index has a valid number of 1

    In the debugger I can see the PTR2FDc collection object and it does have an object in the collection at index 1. It is the correct object.

    There is no error code

    Public Sub PrintFDcollection(ByVal Wrkbk As Workbook, ByVal WrkSht4Printout As Worksheet, ByVal FieldDataCollection As MeasurementCollection)
        Dim Ptr2FDc As MeasurementCollection
        Dim LabelRow As Long
        Dim DataRow As Long
        Dim Row As Long
        Dim Index As Long
        Dim EndRowNum As Long
        Const ElevationIDColumn = 1
        Const X_CoordinateColumn = 2
        Const Y_CoordinateColumn = 3
        Const ElevationColumn = 4
        Const ElevationTypeColumn = 5
        
        With Wrkbk
            With WrkSht4Printout
    '           Instantiate FieldDataCollection (copy of original) as a pointer
                Set Ptr2FDc = FieldDataCollection
            
    '           store column labels in FieldDataCollection object
                   LabelRow = 1
                   .Cells(LabelRow, ElevationIDColumn).value = Ptr2FDc.IDColumnLabel
                   .Cells(LabelRow, X_CoordinateColumn).value = Ptr2FDc.X_CoordinateColumnLabel
                   .Cells(LabelRow, Y_CoordinateColumn).value = Ptr2FDc.Y_CoordinateColumnLabel
                   .Cells(LabelRow, ElevationColumn).value = Ptr2FDc.ElevationColumnLabel
                   .Cells(LabelRow, ElevationTypeColumn).value = Ptr2FDc.ElevationTypeColumnLabel
    '
    '           for as many Measurements exist in FieldData
                DataRow = 2
                EndRowNum = Ptr2FDc.count + DataRow
                For Row = DataRow To Ptr2FDc.count + DataRow
    '              read MeasurementObj data into worksheet
                    Index = Row - 1
                   .Cells(Row, ElevationIDColumn).value = Ptr2FDc(Index).ID
                   
                   .Cells(Row, X_CoordinateColumn).value = Ptr2FDc(Index).Coordinates.X
                   .Cells(Row, Y_CoordinateColumn).value = Ptr2FDc(Index).Coordinates.Y
                   
                   
                   .Cells(Row, ElevationColumn).value = Ptr2FDc(Index).Elevation
                   .Cells(Row, ElevationTypeColumn).value = Ptr2FDc(Index).ElevationType
                 Next
            End With
        End With
    End Sub
    Last edited by JBeaucaire; 05-30-2017 at 02:05 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Having difficulty with exiting a Do loop
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-17-2014, 10:03 PM
  2. How do i loop prematurely?
    By djblois1 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-16-2012, 12:15 PM
  3. Problem with do loop - does not appear to be exiting
    By jbd99 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-29-2012, 05:17 AM
  4. Macro terminates prematurely
    By aljanga in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-26-2009, 12:21 PM
  5. Not exiting For loop
    By gshock in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-13-2008, 03:50 PM
  6. New question about exiting a loop!
    By Canuckbulldog in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-18-2008, 08:36 AM
  7. Function exists prematurely
    By brain in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-31-2006, 11:20 AM
  8. Exiting a Do Loop on error
    By Cloudfall in forum Excel General
    Replies: 7
    Last Post: 11-02-2005, 06:17 PM

Tags for this Thread

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