Results 1 to 2 of 2

Endless loop?

Threaded View

  1. #1
    Registered User
    Join Date
    11-17-2015
    Location
    123
    MS-Off Ver
    10
    Posts
    3

    Endless loop?

    Hi,

    Can anyone help me identify why I'm getting the following errors? "method clearcontents of object range failed" and sometimes "method apply of object sort failed"

    The first part of the code (prior to sorting) works fine by itself and when I added the sorting aspect it actually worked at first--I had the workbook split into different windows. It seems I'm encountering an endless loop but I'm a vba noob and not sure how to fix this. I pasted an image below so you can visualize what's going on. Thanks!

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    Dim i                   As Long
    
        If Not Intersect(ActiveCell, Range("Situations")) Is Nothing Then
            Range("Situation").Value = ActiveCell.Value
        ElseIf Not Intersect(ActiveCell, Range("Hands")) Is Nothing Then
            For i = 1 To 4
                If Range("Card" & i).Value = "" Then
                    Range("Card" & i).Value = ActiveCell.Value
                    Exit For
                End If
            Next i
        ElseIf Not Intersect(ActiveCell, Range("Reset")) Is Nothing Then
            Range("I16:M16").ClearContents
        End If
         ActiveWorkbook.Worksheets("Output").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Output").Sort.SortFields.Add Key:=Range("T1:T4"), _
            SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
            "Ac,Kc,Qc,Jc,Tc,9c,8c,7c,6c,5c,4c,3c,2c,Ad,Kd,Qd,Jd,Td,9d,8d,7d,6d,5d,4d,3d,2d,Ah,Kh,Qh,Jh,Th,9h,8h,7h,6h,5h,4h,3h,2h,As,Ks,Qs,Js,Ts,9s,8s,7s,6s,5s,4s,3s,2s" _
            , DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Output").Sort
            .SetRange Range("T1:T4")
            .Header = xlGuess
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    End Sub

    2f77918de675bb96dc41f025d0ec6550.png
    Attached Images Attached Images

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] endless loop for listbox_click()
    By joseph.davidow in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-15-2016, 08:24 AM
  2. [SOLVED] endless loop
    By ammartino44 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-25-2015, 02:17 PM
  3. Endless loop
    By kathhying in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-28-2011, 01:17 PM
  4. Endless Loop?
    By teaker in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-16-2009, 10:39 AM
  5. Endless loop
    By freddie mac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-01-2006, 10:25 AM
  6. endless loop help
    By John in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-26-2005, 12:05 PM
  7. [SOLVED] Endless loop?
    By John in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 08-02-2005, 02:05 PM

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