替换Excel宏424错误对象必需

时间:2014-10-14 19:33:28

标签: excel vba replace

我正在尝试根据另一列替换单元格内容

我的替换函数抛出424错误Object Required

Public Sub OTherPN()     CurrVal = ActiveCell.Value'获取单元格的当前值

While CurrVal <> " " And NextVal <> " " ' Checks for the condition if the next cell down is blank or does it have a command to STOP
    CurrVal = ActiveCell.Value
    MyLD = ActiveCell.Offset(0, 1).Cells
    ActiveCell.Offset(1, 0).Select
    NextVal = ActiveCell.Value


    While NextVal = CurrVal

   'This is throwing an error     
        MyLD.Replace What:=ActiveCell.Offset(0, 2).Value, Replacement:=ActiveCell.Offset(0, 3).Value, _
        LookAt:=xlPart, MatchCase:=False

        ActiveCell.Offset(1, 0).Select
        NextVal = ActiveCell.Value

    Wend
Wend

End Sub

有谁能告诉我为什么会收到错误?

1 个答案:

答案 0 :(得分:0)

如果您将手表放在MyLD上,您会注意到它从未设置过值,因为在为变量分配范围时需要使用set命令

替换

MyLD = ActiveCell.Offset(0, 1).Cells

Set myLD = ActiveCell.Offset(0, 1).Cells

你应该有更好的运气。