Consulting

Results 1 to 12 of 12

Thread: Solved: Subscript out of range

  1. #1

    Solved: Subscript out of range

    I am testing on this block of code, it is in the rough draft stages. I breaks at this line- [VBA]Worksheets("EC Products").Range("J4:J" & LRowc).Replace "39208", "5-6", xlWhole, False
    [/VBA] which is stumping me. The workbook is open and I have checked the spelling of the sheet name. All looks ok...

    [VBA]
    Sub DougsFindAndReplacev2()
    Dim Wsc As Worksheet
    Dim c As Range, rng As Range
    Dim LRowc As Long
    Dim shCalcSetting As Long
    Set Wsc = Workbooks("Complete_Upload_File.xls").Worksheets("EC Products")
    LRowc = lr(Wsc, 1)
    Set rng = Wsc.Range("J4:J" & LRowc)
    shCalcSetting = Application.Calculation
    'Application.ScreenUpdating = false
    Application.Calculation = xlManual


    'With Wsc
    'For Each c In rng
    'c.Value.Replace "39208", "5-6", xlWhole, False
    'End With
    'Next c

    Worksheets("EC Products").Range("J4:J" & LRowc).Replace "39208", "5-6", xlWhole, False

    ' Range("M4:M" & LRowf).Replace "L", "Lg", xlWhole, False
    ' Range("M4:M" & LRowf).Replace "LARGE", "Lg", xlWhole, False
    ' Range("M4:M" & LRowf).Replace "LG", "Lg", xlWhole, False
    ' Range("M4:M" & LRowf).Replace "LRG", "Lg", xlWhole, False
    ' Range("M4:M" & LRowf).Replace "L/Xl", "Lg/Xl", xlWhole, False
    'End With
    ActiveSheet.Calculate
    Application.Calculation = shCalcSetting
    Application.ScreenUpdating = True
    End Sub

    [/VBA]
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  2. #2
    "J4:J".........??

    EDIT: oops sorry that bit works ok

  3. #3
    That is finding the last used cell in the row
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  4. #4
    And it is accurate, it finds the last row is 121453
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  5. #5
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    Are you using XL2007 now? You can't have row 121,453 otherwise!
    Regards,
    Rory

    Microsoft MVP - Excel

  6. #6
    [vba]Worksheets("Sheet1").Columns("A").Replace What:="SIN", Replacement:="COS", SearchOrder:=xlByColumns, MatchCase:=True [/vba]I am on office 2000, so i guess i should think about that before i make attempts at helping people.This is the only example i found where it seems to be decared differenty.but it could be perfectly ok depending on your version. cheers

  7. #7
    Haha!
    No that was a typo-
    12,453
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  8. #8
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    Yup - it should be:
    .Replace "39208", "5-6", xlWhole, , False
    or use named arguments.
    Regards,
    Rory

    Microsoft MVP - Excel

  9. #9
    Daniel,
    No worries mate. I am on 2003 so that was fine. But that is not the issue I don't believe.
    From my experience- the error is when it cannot find the workbook or worksheet.
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  10. #10
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    No, the issue is that you are supplying False as the SearchOrder parameter. The acceptable values for the XlSearchOrder enum are 1 or 2 and False ( zero) is not valid.
    Regards,
    Rory

    Microsoft MVP - Excel

  11. #11
    Rory-
    Brilliant- thanks.

    Note* Daniel and Rory- the experience I have had w/ RT Error 9 Out of range as I stated was the book or sheet was not open. I had yet to experience it when a argument was missing, or in this case out of order.

    BTW: Is there are error reference list that will show what type errors occur w/ which error messages?
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  12. #12
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    I'm not aware of any particular references for errors. The descriptions are usually slightly helpful apart from the generic Application errors.
    This one is out of range because the item you are trying to refer to (in this case in an Enum) does not exist, so it's the same basic cause as the worksheet name being incorrect.
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

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