VBA代码问题?
Sub剔除退货()DimpinmAsString,shulAsInteger,jineAsInteger,str1AsStringDimmAsIntegerFori=3T...
Sub 剔除退货()
Dim pinm As String, shul As Integer, jine As Integer, str1 As String
Dim m As Integer
For i = 3 To 400
Worksheets("Sheet2").Activate
If Application.Search("供应商", Cells(i, 2)) > 0 Then
'取汉字以外的字符
For k = 1 To Len(Cells(i, 2))
If Not Asc(Mid(Cells(i, 2), k, 1)) < 0 Then
str1 = ""
str1=str1&mid(cells(i,2),k,1)
End If
Next k
m = i
lp1:
pinm=str1&cells(m+5,3)
shul = Cells(m + 5, 8)
jine = Cells(m + 5, 11)
Worksheets("Sheet1").Activate
'↓找到同名行 剔除
For j = 2 To ActiveSheet.UsedRange.Rows.Count
If Cells(j, 7) = pinm Then
Cells(j, 7).EntireRow.Interior.ColorIndex = 43
Cells(j, 11) = Cells(j, 11) - shul
Cells(j, 15) = Cells(j, 15) - jine
Exit For
End If
Next j
Worksheets("Sheet2").Activate
While Cells(m + 6, 3) <> ""
m = m + 1
GoTo lp1
Wend
'↑找到同名行 剔除
End If
Next i
End Sub
请高手帮看看,上面代码问题在哪里,总提示str1=str1&mid(cells(i,2),k,1) 这行报红色 展开
Dim pinm As String, shul As Integer, jine As Integer, str1 As String
Dim m As Integer
For i = 3 To 400
Worksheets("Sheet2").Activate
If Application.Search("供应商", Cells(i, 2)) > 0 Then
'取汉字以外的字符
For k = 1 To Len(Cells(i, 2))
If Not Asc(Mid(Cells(i, 2), k, 1)) < 0 Then
str1 = ""
str1=str1&mid(cells(i,2),k,1)
End If
Next k
m = i
lp1:
pinm=str1&cells(m+5,3)
shul = Cells(m + 5, 8)
jine = Cells(m + 5, 11)
Worksheets("Sheet1").Activate
'↓找到同名行 剔除
For j = 2 To ActiveSheet.UsedRange.Rows.Count
If Cells(j, 7) = pinm Then
Cells(j, 7).EntireRow.Interior.ColorIndex = 43
Cells(j, 11) = Cells(j, 11) - shul
Cells(j, 15) = Cells(j, 15) - jine
Exit For
End If
Next j
Worksheets("Sheet2").Activate
While Cells(m + 6, 3) <> ""
m = m + 1
GoTo lp1
Wend
'↑找到同名行 剔除
End If
Next i
End Sub
请高手帮看看,上面代码问题在哪里,总提示str1=str1&mid(cells(i,2),k,1) 这行报红色 展开
展开全部
追问
追答
最好的办法把全表数据读入数组里面,这样速度会快许多许多,例如:
arr1 = Sheets(1).UsedRange
以后使用arr1(i, 2)速度会非常快,而且不受切换工作表的影响。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询