+ Reply to Thread
Results 1 to 8 of 8

Help with error run-time error '9" (subscript out of Range)

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-31-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    191

    Help with error run-time error '9" (subscript out of Range)

    Hello All,

    this is in regards to my previous post

    https://www.excelforum.com/excel-gen...heet-name.html
    Im using the code below but when Im Adding, Deleting rows it keep showing me the error.


    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Intersect(Target, Range("$B:$C")) Is Nothing Then Exit Sub
    
    Dim Lot1() As String
    Dim Lot2() As String
    
    
    Lot1 = Split(Cells(Target.Row, "B"), " ")
    Lot2 = Split(Cells(Target.Row, "C"), " ")
    Sheets(1).Name = Lot1(UBound(Lot1)) & " vs " & Lot2(UBound(Lot2))
    
    End Sub
    Please help me to remove the popping up error.
    Attached is the file that Im using.


    Thank you
    Attached Files Attached Files
    Last edited by thong127; 05-02-2018 at 01:40 PM. Reason: Upload the sample file

  2. #2
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: Help with error run-time error '9" (subscript out of Range)

    Lot1 = Split(Cells(Target.Row, "B").value, " ")

  3. #3
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,132

    Re: Help with error run-time error '9" (subscript out of Range)

    Maybe
    If Intersect(Target, Range("$B:$C")) Is Nothing Then Exit Sub
    If Range("B" & Target.Row) = "" Or Range("C" & Target.Row) = "" Then Exit Sub

  4. #4
    Forum Contributor
    Join Date
    01-31-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    191

    Re: Help with error run-time error '9" (subscript out of Range)

    Hi Tim,

    Thanks for the quick reply. I tried putting your code but still giving me the same error.

    I would appreciate if you can make work around.

    Thank you.

  5. #5
    Forum Contributor
    Join Date
    01-31-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    191

    Re: Help with error run-time error '9" (subscript out of Range)

    Hi Fluff13,

    I tried to insert your code
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Intersect(Target, Range("$B:$C")) Is Nothing Then Exit Sub
    If Range("B" & Target.Row) = "" Or Range("C" & Target.Row) = "" Then Exit Sub
    
    Dim Lot1() As String
    Dim Lot2() As String
    
    
    Lot1 = Split(Cells(Target.Row, "B"), " ")
    Lot2 = Split(Cells(Target.Row, "C"), " ")
    Sheets(1).Name = Lot1(UBound(Lot1)) & " vs " & Lot2(UBound(Lot2))
    
    End Sub
    but when I tried to copy and paste some data to column C it gives me a Run-time error 1004.

    thank you

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,132

    Re: Help with error run-time error '9" (subscript out of Range)

    If your are pasting the numbers try
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Intersect(Target, Range("$B:$C")) Is Nothing Then Exit Sub
    If Range("B" & Target.Row) = "" Or Range("C" & Target.Row) = "" Then Exit Sub
    
    Dim Lot1() As String
    Dim Lot2() As String
    
    
    Lot1 = Split(Cells(Target.Row, "B"), " ")
    Lot2 = Split(Cells(Target.Row, "C"), " ")
    Sheets(1).Name = Format(Lot1(UBound(Lot1)), "#,##0.00") & " vs " & Format(Lot2(UBound(Lot2)), "#,##0.00")
    
    End Sub

  7. #7
    Forum Contributor
    Join Date
    01-31-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    191

    Re: Help with error run-time error '9" (subscript out of Range)

    Thanks Fluff13, It works like a charm!
    Last edited by thong127; 05-02-2018 at 02:18 PM.

  8. #8
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,132

    Re: Help with error run-time error '9" (subscript out of Range)

    Glad to help & thanks for the feedback

+ 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. VBA Error - Run Time Error 9 - Subscript out if range
    By theskyscraper1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-16-2017, 09:07 PM
  2. "Run-time error '9': Subscript out of range" in some computers!
    By m.zaeim in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-14-2016, 04:03 PM
  3. "Run-time error '9': Subscript out of range" when referencing between workbooks
    By roberts23 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-08-2014, 10:33 AM
  4. [SOLVED] "run time error 9 subscript out of range" Help?
    By AMV in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-24-2014, 04:54 PM
  5. [SOLVED] Run-time error '9': subscript out of range - error occurs on multiple computers except one
    By BrettE in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-06-2014, 11:19 PM
  6. Replies: 1
    Last Post: 12-15-2011, 10:59 AM
  7. Error msgs: "Object varible or with block variable not set"; "subscript out of range"
    By menyanthe in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-26-2009, 04:58 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