+ Reply to Thread
Results 1 to 7 of 7

Code skips on Run Mode but runs fine on F8 (Debug Mode)

Hybrid View

  1. #1
    Registered User
    Join Date
    04-26-2013
    Location
    DR
    MS-Off Ver
    Excel 2010
    Posts
    14

    Question Code skips on Run Mode but runs fine on F8 (Debug Mode)

    Hi! I have a code that finds the duplicates of column A and merges some columns on the same row according to how many duplicates are in the column A.

    When I run the code pressing F8 everything works marvelous but when I run it as it's supposed to run (F5) then it just won't merge anything.

    Can anyone help me, please? This is driving me nuts and it's the last thing I need to fix for presenting a project to my boss


    Application.DisplayAlerts = False
        With Application.WorksheetFunction
        Dim count As Integer
            For i = 4 To 40
                If Sheet3.Range("A" & i) = Sheet3.Range("A" & i).Offset(1, 0) And Sheet3.Range("A" & i) <> "" Then
                    count = .CountIf(Sheet3.Range("A4:A44"), Sheet3.Range("A" & i))
                    Sheet3.Range("A" & i & ":" & "A" & i + count - 1).Select
                    Selection.Merge
                    Sheet3.Range("N" & i & ":" & "N" & i + count - 1).Select
                    Selection.Merge
                    Sheet3.Range("B" & i & ":" & "B" & i + count - 1).Select
                    Selection.Merge
                    Sheet3.Range("C" & i & ":" & "C" & i + count - 1).Select
                    Selection.Merge
                    Sheet3.Range("D" & i & ":" & "D" & i + count - 1).Select
                    Selection.Merge
                    Sheet3.Range("E" & i & ":" & "E" & i + count - 1).Select
                    Selection.Merge
                    Sheet3.Range("F" & i & ":" & "F" & i + count - 1).Select
                    Selection.Merge
                    Sheet3.Range("G" & i & ":" & "G" & i + count - 1).Select
                    Selection.Merge
                    Sheet3.Range("H" & i & ":" & "H" & i + count - 1).Select
                    Selection.Merge
                    Sheet3.Range("I" & i & ":" & "I" & i + count - 1).Select
                    Selection.Merge
                    Sheet3.Range("J" & i & ":" & "J" & i + count - 1).Select
                    Selection.Merge
                    Sheet3.Range("M" & i & ":" & "M" & i + count - 1).Select
                    Selection.Merge
                    i = i + count - 1
                End If
            Next
        End With
    Thanks for reading ^^

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Code skips on Run Mode but runs fine on F8 (Debug Mode)

    Can you post a workbook with sample data?
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Registered User
    Join Date
    04-26-2013
    Location
    DR
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Code skips on Run Mode but runs fine on F8 (Debug Mode)

    Berlan... you are a GENIUS. Simplyfing the code made it work. Thank you very much! +rep for you ^^
    Quote Originally Posted by berlan View Post
    Try this (only cleaning the code a bit), for me this actually works:

    Sub main()
    
        Dim i As Long, count As Long
        Dim Rng As Range
    
        Application.DisplayAlerts = False
    
        With Sheet3
    
            Set Rng = .Range("A4:A44")
            For i = 4 To 40
                If .Range("A" & i) = .Range("A" & i).Offset(1, 0) And .Range("A" & i) <> "" Then
                    count = WorksheetFunction.CountIf(Rng, .Range("A" & i))
                    .Range("A" & i & ":" & "A" & i + count - 1).Merge
                    .Range("N" & i & ":" & "N" & i + count - 1).Merge
                    .Range("B" & i & ":" & "B" & i + count - 1).Merge
                    .Range("C" & i & ":" & "C" & i + count - 1).Merge
                    .Range("D" & i & ":" & "D" & i + count - 1).Merge
                    .Range("E" & i & ":" & "E" & i + count - 1).Merge
                    .Range("F" & i & ":" & "F" & i + count - 1).Merge
                    .Range("G" & i & ":" & "G" & i + count - 1).Merge
                    .Range("H" & i & ":" & "H" & i + count - 1).Merge
                    .Range("I" & i & ":" & "I" & i + count - 1).Merge
                    .Range("J" & i & ":" & "J" & i + count - 1).Merge
                    .Range("M" & i & ":" & "M" & i + count - 1).Merge
                    i = i + count - 1
                End If
            Next
    
        End With
    
        Application.DisplayAlerts = True
    
    End Sub
    Solus, unfortunately, I can't as it contains company's sensitive info.
    Quote Originally Posted by Solus Rankin View Post
    Can you post a workbook with sample data?

  4. #4
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Code skips on Run Mode but runs fine on F8 (Debug Mode)

    Quote Originally Posted by RaquelAR View Post
    Berlan... you are a GENIUS. Simplyfing the code made it work. Thank you very much! +rep for you ^^

    Solus, unfortunately, I can't as it contains company's sensitive info.


    Oh many thanks!! You're welcome!

    All best

  5. #5
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Code skips on Run Mode but runs fine on F8 (Debug Mode)

    Try this (only cleaning the code a bit), for me this actually works:

    Sub main()
    
        Dim i As Long, count As Long
        Dim Rng As Range
    
        Application.DisplayAlerts = False
    
        With Sheet3
    
            Set Rng = .Range("A4:A44")
            For i = 4 To 40
                If .Range("A" & i) = .Range("A" & i).Offset(1, 0) And .Range("A" & i) <> "" Then
                    count = WorksheetFunction.CountIf(Rng, .Range("A" & i))
                    .Range("A" & i & ":" & "A" & i + count - 1).Merge
                    .Range("N" & i & ":" & "N" & i + count - 1).Merge
                    .Range("B" & i & ":" & "B" & i + count - 1).Merge
                    .Range("C" & i & ":" & "C" & i + count - 1).Merge
                    .Range("D" & i & ":" & "D" & i + count - 1).Merge
                    .Range("E" & i & ":" & "E" & i + count - 1).Merge
                    .Range("F" & i & ":" & "F" & i + count - 1).Merge
                    .Range("G" & i & ":" & "G" & i + count - 1).Merge
                    .Range("H" & i & ":" & "H" & i + count - 1).Merge
                    .Range("I" & i & ":" & "I" & i + count - 1).Merge
                    .Range("J" & i & ":" & "J" & i + count - 1).Merge
                    .Range("M" & i & ":" & "M" & i + count - 1).Merge
                    i = i + count - 1
                End If
            Next
    
        End With
    
        Application.DisplayAlerts = True
    
    End Sub

  6. #6
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Code skips on Run Mode but runs fine on F8 (Debug Mode)

    However, I feel there may be more efficient ways ways to do this

  7. #7
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Code skips on Run Mode but runs fine on F8 (Debug Mode)

    RequelAR, you can always replace any sensitive data with dummy data

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 3
    Last Post: 03-29-2012, 01:58 PM
  2. VBA code only works correctly in Debug mode
    By tpthatsme in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-09-2012, 12:51 PM
  3. Macro Runs fine in debug but not from ComboBox
    By jaslake in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 02-25-2009, 10:17 AM
  4. [SOLVED] Excel 2000 Code works except in debug mode
    By Bob Smedley in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-23-2006, 09:25 PM
  5. Get in DEBUG mode on workbook open
    By Anthony Fok in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-28-2005, 01:30 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