Results 1 to 20 of 20

Loop eval cell and actions not capturing last row

Threaded View

  1. #1
    Registered User
    Join Date
    01-16-2021
    Location
    Australia
    MS-Off Ver
    Office 2019
    Posts
    7

    Loop eval cell and actions not capturing last row

    I have written vba for a macro which loops through a data extract, looks if a row contains a value in a certain column and if so, then performs some data copy/move functions. This is to loop until the end of the rows of data in the file.

    Everything works well except the last row of data if it contains data in the requisite column, doesn't trigger the actions. It's fixed if I re-run the macro. But ideally it would complete property in one run. Given I am setting finalrow at the beginning and then inserting rows, I am guessing this is causing the last row to be missed. But I added an incremental +1 to finalrow within the loop which seemed to work for all rows except last. Not sure why. Any help appreciated (i've removed code not critical to the issue):


    Dim finalrow As Integer 'final row of data available
    Dim ws As Worksheet ' worksheet
    
    Set ws = ThisWorkbook.Worksheets("Axis_Inv_Data")
    ws.Activate
    finalrow = Cells(Rows.Count, 1).End(xlUp).Row
    
    
    For i = 2 To finalrow
        '1 find row with km
        If IsEmpty(ws.Cells(i, 9)) = False Then
    
                
        '2 insert row after for kms
                Rows(i + 1).Insert
                
        '3 move km data to new row
                
        '4 copy shift data to new km row
                
         ' add one more row to total to ensure we don't miss last row
         finalrow = finalrow + 1
         
        End If
        
    Next i
    
    
    End Sub
    Last edited by alansidman; 01-16-2021 at 01:08 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 7
    Last Post: 09-07-2016, 04:45 AM
  2. [SOLVED] Loop through workbook applying two different actions to two sets of sheets
    By ksayet in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-26-2015, 06:03 PM
  3. [SOLVED] Repeat actions in a Loop
    By abduljaleel.mca in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-19-2013, 11:03 AM
  4. sum loop not capturing all values
    By DFrank231 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-19-2011, 05:33 PM
  5. Macro to loop actions until empty cell
    By RobbieMoulton in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-29-2011, 02:59 AM
  6. Formulas, employee eval date &....
    By noli414 in forum Excel General
    Replies: 5
    Last Post: 07-15-2008, 07:27 PM
  7. Eval function with sum
    By raffaello_ in forum Excel General
    Replies: 0
    Last Post: 05-31-2006, 06:51 AM

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