-1

下面的代码在 Excel 2008 中给出了不匹配或范围错误。我该如何解决?

Sub PEC()
    Dim PEC As String, result As Integer
    PEC = Range("AE2:AE26848").Value    
    If PEC = "A.06" Then result = 1    
    Range("AO2:AO26848").Value = result
End Sub
4

2 回答 2

0
Sub PEC()
    For x = 2 to 26848
        If Range("AE" & x) = "A.06" Then Range("AO" & x) = 1
    Next x
End Sub
于 2014-06-19T20:00:17.727 回答
0

我建议使用以下代码。它可能看起来更复杂,但它确实做得更好,更强大。它只是将您的输入和输出范围分配为 SrcRng 和 DstRng。范围的 FIND 方法是检查特定值的好方法。

子 PEC()

Dim SrcRng As Range
Dim DstRng As Range
Dim rcell As Range

Set SrcRng = Range ("AE2:AE26848")
Set DstRng = Range("AO2:AO26848")

Set rcell = SrcRng.Find(what:="A.06", after:=SrcRng.Cells(1, 1), _
                    LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
                    SearchDirection:=xlNext, MatchCase:=False)

If Not rcell Is Nothing Then
    DstRng.Value = 1
End If

结束子

于 2014-06-19T20:14:34.757 回答