Consulting

Results 1 to 6 of 6

Thread: run time error '9' subscript out of range

  1. #1
    VBAX Regular
    Joined
    Nov 2018
    Posts
    21
    Location

    run time error '9' subscript out of range

    get a run time error '9' subscript out of range

    the error occurs on line 6 thru 10

    funny thing is this code works most of the time.




    Sub CloseMe()Call MessageBoxTimer5
    Sheets("Final Use").Range("D11").ClearContents
    Worksheets("Sheet2").Range("F1").Copy
    Worksheets("Final Use").Range("D13").PasteSpecial Paste:=xlPasteValues
    Sheets("Final Use").Range("D11").ClearContents
    Sheets("QAT USE").Range("C11").ClearContents
    Sheets("QAT USE").Range("C13").ClearContents
    Sheets("QAT USE").Range("C15").ClearContents
    Sheets("QAT USE").Range("C17").ClearContents
    Sheets("QAT USE").Range("C19").ClearContents
    Application.DisplayAlerts = False
    'ThisWorkbook.Save
    'ThisWorkbook.Close
    End Sub

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Without a failing sample, this is only a guess ...

    Make sure that "QAT USE" does not have leading or trailing spaces
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Regular
    Joined
    Nov 2018
    Posts
    21
    Location
    assuming your meaning spaces in the cells being cleared there are none.

    i have it set up so only certain data can be entered in the cells and then if left open for too long the workbook closes automatically resting all cells back to a default value or deletes all data. the error only occurs sometimes. i have even tried to manipulate the program to it force it to produce the error and i cant find out why the error is occurring.

  4. #4
    That error means that you don't have a sheet called "QAT USE" in the Active workbook

  5. #5
    VBAX Regular
    Joined
    Nov 2018
    Posts
    21
    Location
    there is a sheet called QAT USE

    as i said before the program works and then out of nowhere it malfunctions

  6. #6
    It will work if the workbook that contains the "QAT USE" is the active workbook at run time & it will fail with the error you specified if any other workbook is active when you run the code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •