+ Reply to Thread
Results 1 to 7 of 7

need help correcting a macro-run-time erro 6 - overflow

Hybrid View

JMJ123 need help correcting a... 04-25-2013, 05:11 PM
rcm Re: need help correcting a... 04-25-2013, 05:15 PM
JMJ123 Re: need help correcting a... 04-25-2013, 07:45 PM
rcm Re: need help correcting a... 04-26-2013, 12:46 AM
JMJ123 Re: need help correcting a... 04-26-2013, 12:41 PM
rcm Re: need help correcting a... 04-26-2013, 02:03 PM
JMJ123 Re: need help correcting a... 04-29-2013, 12:05 PM
  1. #1
    Registered User
    Join Date
    03-27-2013
    Location
    Arizona
    MS-Off Ver
    Excel 2003
    Posts
    13

    need help correcting a macro-run-time erro 6 - overflow

    Dear Excel Expert,

    I created the following macro to run on a selected range, but if I select for example five cells in a column the macro does not stop at the fifth selection but continues to the very end of the list. I arbitrarily set the do until to .1 because I did not want the "do loop" to stop the macro but rather the other loop to stop it. I think this might be the problem though. And sometimes the macro doesn't run at all but gives me a Run-Time error - 6 - overflow.

    Please help. Thanks Andrew
    Sub Test8()
    '
    ' Test8 Macro
    ' Macro recorded 4/25/2013 by .
    '
    ' Keyboard Shortcut: Ctrl+Shift+Z
    '
    'This part is from "Variable Range and Input box" located in the folder
    'Running a Macro on range(this is the folders approx. name)
        
        Dim myRange As Range
     
        Set myRange = Application.InputBox(Prompt:= _
            "Please Select a Range", _
            Title:="InputBox Method", Type:=8)
     
        If myRange Is Nothing Then
            ' Range is blank
        Else
            myRange.Select
        End If
        
      'The following is the loop part. This is from, "Create a loop". This is
      'document with the accompaning excel wk with multiple loops.
      
      ' This loop repeats a fixed number of times getting its reference from elsewhere
        Dim i As Integer
        Dim intRowCount As Integer
        intRowCount = myRange.CurrentRegion.Rows.Count
        For i = 1 To intRowCount
        
        'The nested part is a loop to perform the macro. It is also in the
        'document, "Create a loop" but it is not the same author. It is a
        'separate author.
        
    'Here is my macro to format the cell
    'Print ActiveCell.Characters.Count
    With ActiveCell.Characters(1).Font 'counts 1 character over
    'from the left, then seclects that cell and the next cell
    .Color = RGB(0, 0, 0) ' black
    End With
    
        'Print ActiveCell.Characters.Count
    With ActiveCell.Characters(2).Font 'counts 2 characters from left
    ' to right and then below it is colored.
    .Color = RGB(0, 0, 255)
    End With
        
        With Selection.Interior
            .ColorIndex = 8
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
        End With
          
        ActiveCell.Offset(1, 0).Select
           
       Next i 'This is end part of the loop
    
    
    End Sub
    Last edited by Leith Ross; 04-26-2013 at 01:25 PM. Reason: Added Code Tags

  2. #2
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: need help correcting a macro-run-time erro 6 - overflow

    the best calculation for the last row used is

    introwcount=range("A"&rows.count).end(xlup).row
    selecting a column that is continuously filled up until the end.
    Last edited by Leith Ross; 04-26-2013 at 01:26 PM. Reason: Added Code Tags

  3. #3
    Registered User
    Join Date
    03-27-2013
    Location
    Arizona
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: need help correcting a macro-run-time erro 6 - overflow

    Thank you rcm for the reply. Where in the macro do I insert your suggested correction. And do I need to delete any of my lines?

  4. #4
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: need help correcting a macro-run-time erro 6 - overflow

    your problem is deeper than I thought... my original reply is not part of the solution...

    if the range is entered like "A1:a5" then the starting row and ending rows can be established...otherwise

  5. #5
    Registered User
    Join Date
    03-27-2013
    Location
    Arizona
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: need help correcting a macro-run-time erro 6 - overflow

    Hi rcm,

    Thanks for the reply. I figured out the error. I changed the loop to a for next loop and now it works well.

    Can I ask you a separate question is it possible to copy color coding of text from one list of names to another, ie one column of names has color formatting and the other doesn't so I need to copy from the color coded list to the non-color coded list.

    Thanks again,

    Andrew

  6. #6
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: need help correcting a macro-run-time erro 6 - overflow

    in VBA yes let assume you want to copy the font color of cells(1,"A") into cells(1,"D").

    cells(1,"A").font.color=cells(1,"D").font.color

  7. #7
    Registered User
    Join Date
    03-27-2013
    Location
    Arizona
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: need help correcting a macro-run-time erro 6 - overflow

    Hi rcm,

    I tried that line of code but could not get it to work. Could you please put it in a short macro so that I know for sure I am using it correctly?

    Thanks,

    Andrew

+ 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