Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 3337|回复: 2

VBA代码报错,这个代码会在标红部分报错,帮忙修改下

[复制链接]
发表于 2019-4-26 08:07 | 显示全部楼层 |阅读模式
1学分


Sub 狀態判斷()
Dim i As Long, s()
i = 2
Range("aj2:AJ1048576") = ""
s = Range("a1:AK300000")
Q = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To Q Step 1
r = s(i, 37).End(xlToLeft).Column
If s(i, 37) <> "" Then
On Error Resume Next
If s(i, 37) = "Scraped" Or s(i, 37) = "SCRAP" Then
    If r = 1 Or r = 35 Or r = 34 Then
    s(i, 29) = "Fail"
    s(i, 22) = "Fail"
    s(i, 15) = "Fail"
    s(i, 8) = "Scraped"
    s(i, 36) = "Scraped"
    End If
        If r = 29 Or r = 28 Or r = 27 Then
        s(i, 29) = "Fail"
        s(i, 22) = "Fail"
        s(i, 15) = "Fail"
        s(i, 8) = "Scraped"
        s(i, 36) = "Scraped"
        End If

            If r = 20 Or r = 21 Or r = 22 Then
                    s(i, 22) = "Fail"
                    s(i, 15) = "Fail"
                    s(i, 8) = "Scraped"
                    s(i, 36) = "Scraped"
                    End If

                If r = 13 Or r = 14 Or r = 15 Then
                        s(i, 15) = "Fail"
                        s(i, 8) = "Scraped"
                        s(i, 36) = "Scraped"
                        End If
                    If r = 6 Or r = 8 Or r = 7 Then
                            s(i, 8) = "Scraped"
                            s(i, 36) = "Scraped"
                            End If
End If
'1
On Error Resume Next
If s(i, 37) = "Repair OK" Or s(i, 37) = "KEY OUT" Then
    If r = 1 Or r = 35 Or r = 34 Then
    s(i, 29) = "Fail"
    s(i, 22) = "Fail"
    s(i, 15) = "Fail"
    s(i, 8) = "Fail"
    s(i, 36) = "Pass"
    End If
        If r = 27 Or r = 29 Or r = 28 Then
        s(i, 29) = "Pass"
        s(i, 22) = "Fail"
        s(i, 15) = "Fail"
        s(i, 8) = "Fail"
        s(i, 36) = "Pass"
        End If

            If r = 20 Or r = 21 Or r = 22 Then
                    s(i, 22) = "Pass"
                    s(i, 15) = "Fail"
                    s(i, 8) = "Fail"
                    s(i, 36) = "Pass"
                    End If

                If r = 13 Or r = 14 Or r = 15 Then
                        s(i, 15) = "Pass"
                        s(i, 8) = "Fail"
                        s(i, 36) = "Pass"
                        End If
                    If r = 6 Or r = 8 Or r = 7 Then
                            s(i, 8) = "Pass"
                            s(i, 36) = "Pass"
                            End If

End If
On Error Resume Next
If s(i, 37) <> "Repair OK" And s(i, 37) <> "KEY OUT" And s(i, 37) <> "SCRAP" And s(i, 37) <> "Scraped" Then
    If r = 1 Or r = 35 Or r = 34 Then
    s(i, 29) = "Fail"
    s(i, 22) = "Fail"
    s(i, 15) = "Fail"
    s(i, 8) = "Fail"
    s(i, 36) = "Fail"
    End If
        If r = 27 Or r = 29 Or r = 28 Then
        s(i, 29) = "Fail"
        s(i, 22) = "Fail"
        s(i, 15) = "Fail"
        s(i, 8) = "Fail"
        s(i, 36) = "Fail"
        End If

            If r = 20 Or r = 21 Or r = 22 Then
                    s(i, 22) = "Fail"
                    s(i, 15) = "Fail"
                    s(i, 8) = "Fail"
                    s(i, 36) = "Fail"
                    End If

                If r = 13 Or r = 14 Or r = 15 Then
                        s(i, 15) = "Fail"
                        s(i, 8) = "Fail"
                        s(i, 36) = "Fail"
                        End If
                    If r = 6 Or r = 8 Or r = 7 Then
                            s(i, 8) = "Fail"
                            s(i, 36) = "Fail"
                            End If

End If

End If

Next i

End Sub



最佳答案

查看完整内容

把“r = s(i, 37).End(xlToLeft).Column”换为“r = Cells(i, 37).End(xlToLeft).Column”试试。
发表于 2019-4-26 08:07 | 显示全部楼层
把“r = s(i, 37).End(xlToLeft).Column”换为“r = Cells(i, 37).End(xlToLeft).Column”试试。
回复

使用道具 举报

发表于 2019-4-26 21:46 | 显示全部楼层
s(i, 37)是数组,没有后面的属性方法。换用range对象Cells(i, 37)就行了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-26 19:58 , Processed in 0.294326 second(s), 9 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表