Loop的应用程序定义或对象定义错误

时间:2016-05-17 11:26:26

标签: excel vba

Sheet" Replacement List"低于范围

I2: BELGIUM (KINGDOM OF)    J2: Unsecured Bank Fixed Income K2: Govt Agencies
I3: FRANCE (REPUBLIC OF)    J3: Unsecured Bank Fixed Income k3: Govt Agencies

Sheet" Code"低于范围

F2: BELGIUM (KINGDOM OF)    G2: Unsecured Bank Fixed Income 
F3: FRANCE (REPUBLIC OF)    G3: Unsecured Bank Fixed Income 

我想要的只是(伪代码),

if F2 (BELGIUM (KINGDOM OF)) = I2 (BELGIUM (KINGDOM OF) and G2 (Unsecured Bank Fixed Income) = j2 (Unsecured Bank Fixed Income) then replace G2 (Unsecured Bank Fixed Income) with K2 (Govt Agencies)

我尝试了以下循环,但我得到了应用程序定义或对象定义的错误......有人可以帮帮我吗?

Sub Test2()

Dim x As Long, y As Long

Dim lastrow2 As Long
Dim lastrowStep2 As Long
Dim ShtCode As Worksheet
Dim ShtRplList As Worksheet

Set ShtCode = Sheets("Code")
Set ShtRplList = Sheets("Replacement List")

lastrow2 = ShtCode.Range("F2:G3").Row
lastrowStep2 = ShtRplList.Range("I2:K3").Row

ShtCode.Select

For x = 2 To lastrow2

        For y = 2 To lastrowStep2

        If ShtCode.Cells(x, 6).Value = ShtRplList.Cells(j, 9).Value And ShtCode.Cells(x, 7).Value = ShtRplList.Cells(j, 10).Value Then
           ShtCode.Cells(x, 7).Value = ShtRplList.Cells(j, 11).Value

        End If

        Next y

Next x

End Sub

0 个答案:

没有答案