+ Reply to Thread
Results 1 to 14 of 14

Macro stops working on row

Hybrid View

  1. #1
    Registered User
    Join Date
    12-15-2009
    Location
    Houston, TX, USA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Exclamation Macro stops working on row

    Please look at the attached sheet. I got some help in this forum earlier (http://www.excelforum.com/excel-prog...-column-c.html) and the code i got worked at first, but when i changed the sheet (added columns) and attempted to alter the code accordingly, now the code stops working at line 222.

    I can't tell anything different about the data on lines 223 and so forth that would cause the macro to stop running there, maybe someone with more experience will notice?


    Sheet1 is the original data. Sheet2 is after the code has been run. The item descriptions have been removed.

    Option Explicit
    
    Sub SortRows()
    Dim Rng As Range, Dn As Range, n As Long, ac As Integer
    Set Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
    ReDim ray(1 To Rng.Count, 1 To 14)
    With CreateObject("scripting.dictionary")
    .CompareMode = vbTextCompare
    For Each Dn In Rng
    
    If Dn.Offset(, 9) = "530" Or Dn.Offset(, 9) = "540" Then
    If Not .Exists(Dn.Value & Dn.Next.Value & Dn.Offset(, 9)) Then
    n = n + 1
    .Add Dn.Value & Dn.Next.Value & Dn.Offset(, 9), n
    For ac = 1 To 14
    If ac = 12 Then
    ray(n, ac) = Format(Dn.Offset(, ac - 1), "mm/dd/yyyy")
    Else
    ray(n, ac) = Dn.Offset(, ac - 1)
    End If
    Next ac
    End If
    End If
    Next
    Sheets("Sheet2").Range("A2").Resize(.Count, 14) = ray
    End With
    
    End Sub
    Attached Files Attached Files
    Last edited by smokebreak; 01-22-2010 at 06:00 PM.

  2. #2
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: macro inexplicably stops working on row 225

    I ran your macro and it is not stopping at row 221. There are only 221 entries that are being extracted. The two filter lines
    If Dn.Offset(, 9) = "530" Or Dn.Offset(, 9) = "540" Then
    If Not .Exists(Dn.Value & Dn.Next.Value & Dn.Offset(, 9)) Then
    are restricting the number of entries that you are extracting. Are you sure that these two tests are correct for what you want to do?

  3. #3
    Registered User
    Join Date
    12-15-2009
    Location
    Houston, TX, USA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: macro inexplicably stops working on row 225

    Quote Originally Posted by blane245 View Post
    The two filter lines ...are restricting the number of entries that you are extracting. Are you sure that these two tests are correct for what you want to do?
    Unfortunately I barely can read VBA code, so I'm not really sure, I got this code from someone else on this board and I do not fully understand it. Perhaps could you explain what it means, or better yet, help me fix it to do what I want it to do?

    Going back to my original post, the problem I am trying to solve is that in the raw data, there are often several lines for a unique order number/line number combination. for each Order number/line number combination, I only want to pull out the first time that "Next Stat" = 530 and the first time "Next Stat"=540. Everything else can be deleted.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Macro stops working on row

    Hello smokebreak,

    The code is designed to only copy unique values from sheet to the other. Currently, there are only 221 unique entries on "Sheet1".
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Registered User
    Join Date
    12-15-2009
    Location
    Houston, TX, USA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: Macro stops working on row

    Quote Originally Posted by Leith Ross View Post
    Hello smokebreak,

    The code is designed to only copy unique values from sheet to the other. Currently, there are only 221 unique entries on "Sheet1".
    Should I re-open my original question then, or should I pursue the issue in this thread? My original post is here:
    http://www.excelforum.com/excel-prog...-column-c.html

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Macro stops working on row

    Hello smokebreak,

    Don't start another thread. Leave this one open. What is the macro not doing now that it seemed to be doing before (since you marked the previous post solved)?

  7. #7
    Registered User
    Join Date
    12-15-2009
    Location
    Houston, TX, USA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: Macro stops working on row

    FINALLY a solution that works. Thank you for your persistence to help a stranger, Leith.

  8. #8
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Macro stops working on row

    another way with a Collection
    Option Explicit
    Sub ptest()
        Dim Unqiue As New Collection, cell As Range, pInt, x, y, z, v
        For Each cell In Range("D1", Range("D" & Rows.Count).End(xlUp))
            Unqiue.Add cell.Offset(0, -3).Value & "," & cell.Offset(0, -2).Value & "," & cell.Offset(0, -1).Value & "," & _
                       cell.Value & "," & cell.Offset(0, 1).Value, CStr(cell.Value)
            On Error Resume Next
        Next cell
        x = 1
        For pInt = 1 To Unqiue.Count
            y = 1
            For Each z In Split(Unqiue.Item(pInt), ",")
                Sheets("Sheet3").Cells(x, y).Value = z
                y = y + 1
            Next
            x = x + 1
        Next
    End Sub
    But alas the data has changes since the origonal closed post
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

+ 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