我在分割代码中输出值时遇到问题。它适用于我的代码的if部分,但不适用于我的其他部分。我一直在
运行时错误9 - 下标超出范围
当我跑步时。
Dim SR As Integer
Dim z As Integer
Dim lastrow As Long
Dim str1() As String
Dim str2() As String
Dim avarsplit As Variant
Dim xRg As Range, yRg As Range, yRgD As Range, yRgE As Range, yRgF As Range, yRgG As Range, yRgH As Range, yRgI As Range
SR = 2
z = 1
Do While Worksheets("AppendedData").Cells(SR, 13) <> ""
If Worksheets("AppendedData").Cells(SR, 13) = 1 And Worksheets("AppendedData").Cells(SR, 12) = 0 Then
avarsplit = Split(Worksheets("AppendedData").Cells(SR, 1).Value, " - ")
splitValues = Split(Worksheets("AppendedData").Cells(SR, 1).Value)
Worksheets("AppendedData").Cells(SR, 27).Value = splitValues(0)
Worksheets("AppendedData").Cells(SR, 26).Value = splitValues(1)
z = z + 1
SR = SR + 1
Else:
Worksheets("AppendedData").Select
Worksheets("AppendedData").Cells(SR, 15).FormulaR1C1 = "=3"
Worksheets("AppendedData").Cells(SR, 29).Value = "Delete"
avarsplit = Split(Worksheets("AppendedData").Cells(SR, 1).Value, " - ")
splitValues = Split(Worksheets("AppendedData").Cells(SR, 1).Value)
Worksheets("AppendedData").Cells(SR, 27).Value = splitValues(1) ' ERROR OCCURS HERE!
SR = SR + 1
End If
Loop
谢谢你的评论让我意识到我的测试数据中存在错误,而不是我的代码。
但是我现在想要找出splitValues(1)在分割不起作用时会采取什么值。即,如果细胞是&#34; TEST&#34;而不是&#34; TEST - 123&#34;正如所料。有任何想法吗?
因为我想在拆分失败时做一个if语句来做什么