Results 1 to 7 of 7

macro failing

Threaded View

  1. #1
    Registered User
    Join Date
    06-25-2008
    Posts
    40

    macro failing

    Hi
    I Aam running the following code to transfer info from one workshet to another but it is failing

    I am getting

    run-time error '1004':
    Application- defined or object -defined error

    It work ok the first time but fails the second-third etc

    Any help i would be greatful


    Sub try33511()
    Dim a As New Collection, x, y, i As Long, n As Long, rcount As Long, lrowsupp As Long
    If Sheets("Pivots").[AO1] = "" Then Exit Sub
    Application.ScreenUpdating = 0
    With Sheets("Pivots"): y = .Range(.[AO1], .Cells(Rows.Count, "ao").End(xlUp).Offset(, 1)): End With: rcount = UBound(y)
    With Sheets("reason 33511"): x = .Range(.[a2], .Cells(Rows.Count, "a").End(xlUp).Offset(rcount, 1)): lrowsupp = UBound(x) - UBound(y)
    On Error Resume Next
    For i = 1 To UBound(x)
       If x(i, 1) <> "" Then a.Add i, CStr(x(i, 1))
    Next
    Err.Clear
    For i = 1 To UBound(y)
        a.Add i, CStr(y(i, 1))
        If Err.Number = 0 Then
            n = n + 1
            x(lrowsupp + n, 1) = y(i, 1)
            x(lrowsupp + n, 2) = y(i, 2)
        Else
            x(a.Item(CStr(y(i, 1))), 2) = y(i, 2)
            Err.Clear
        End If
    Next
    .[a2].Resize(UBound(x), 2) = x: End With
    End Sub
    Last edited by belkin; 08-19-2011 at 03:57 AM. Reason: Added code tags - Tile still to be changed by OP

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