简体   繁体   中英

Run-time error9. Subscript out of range error

I am using a code to search other sheets in the same workbook for particular text this option works well on my system however does not work on a different one. Can anyone assist me why.
This is on excel and VBA was used to create the macros and Below is the code

Sub Search_Macro()
'
' Search Macro
'
    Dim Sheet_Name As String
    Dim Search_string As String
    Dim Rng As Range
    
    Sheet_string = 0
    
    
    Sheet_Name = Sheets("Summary").Range("O23").Value
    Sheet_string = Sheets("Summary").Range("O27").Value
    
    If Sheet_string = 0 Then
        MsgBox "Select correct Product and Topic", vbOKOnly
             
        Exit Sub
    End If
                 
                              
    Sheets(Sheet_Name).Select
    Set Rng = Range("A1:Z500").Find(Sheet_string)

    If Rng Is Nothing Then
        Sheets("Summary").Select
        MsgBox "Select correct Product and Topic", vbOKOnly
    Else
        Cells.Find(What:=Sheet_string, After:=Range("A1"), _
        LookIn:=xlFormulas2, LookAt:=xlPart, SearchOrder:=xlByRows, _
        SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
    End If
End Sub

It is just a shot into dark, since no info of what type of error you get on the other system, but I would guess you perhaps either misspelled the sheet name in you input cell O23 or the position of the input cell has changed and the macro code get the content of a different cell.

Be especially careful about spaces vs. underscores in the sheet names, spaces before and after the sheet name. It happens a lot:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM