[英]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这是在 excel 和 VBA 上用于创建宏,下面是代码
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.这只是一个黑暗的镜头,因为没有关于您在其他系统上遇到什么类型的错误的信息,但我猜您可能在输入单元格 O23 或输入单元格的 position 中拼错了工作表名称已更改并且宏代码获取不同单元格的内容。
Be especially careful about spaces vs. underscores in the sheet names, spaces before and after the sheet name.特别注意工作表名称中的空格与下划线、工作表名称前后的空格。 It happens a lot:)
它发生了很多:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.