+ Reply to Thread
Results 1 to 7 of 7

macro failing

Hybrid 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

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: macro failing

    After 34 posts and 3 years subscription you should have known to add codetags....



  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: macro failing

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    PLEASE PM WHEN YOU HAVE DONE THIS AND I WILL DELETE THIS POST
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

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

    Re: macro failing

    Quote Originally Posted by belkin View Post
    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
    thank you!

  5. #5
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: macro failing

    Don't forget to change the title

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

    Re: macro failing

    thanks but i figured it out now

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: macro failing

    Your post does not comply with Rule 9 of our Forum RULES. If you solve a problem yourself before anyone else has responded, please take a moment to describe your solution, chances are some other member will benefit. And please never edit a thread in which someone else has responded.

    If you aren't bothereed then we can't be bothered to help you. In fact take a holiday from posting - 2 weeks ban

    Change the Title or don't bother posting again!

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ 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