我一直在代码中获取所需的对象.为什么? [英] I keep getting an object required on my code. Why?

查看:30
本文介绍了我一直在代码中获取所需的对象.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于这是一个非常基本的问题,我们深感抱歉,但是多年来我一直在努力解决这个问题,无法解决.

I'm sorry if this is a really basic question, but I've been grappling with it for ages and cannot figure it out.

为什么我的代码不断给出对象必需的错误?

Why does my code keep giving an object required error?

Sub MatchUp()

    For Each PastCell In Range("A1:A240")
        For Each FutureCell In Range("P1:P240")
            If FutureCell.Value = PastCell.Value Then
                Range(FutureCell.Offset(0, 1), FutureCell.Offset(0, 9)).Cut _
                        Range(PastCell.Offset(0, 15), PastCell.Offset(0.23))
            End If
        Next
    Next

    Application.CutCopyMode = False

End Sub

推荐答案

您有几个type-o,另外最好避免复制/粘贴.见下文.有更清洁的方法可以执行此操作,但是此(未经测试的)代码应使您到达终点……

You have a couple type-o's, plus it's better to avoid copy/paste. See below. There's cleaner ways of doing this, but this (untested) code should get you to the finish line...

Sub MatchUp()
Dim pastCell As Range, FuturCell As Range


    For Each pastCell In Range("A1:A240").Cells
        For Each FutureCell In Range("P1:P240").Cells
            If FutureCell.Value = pastCell.Value Then
                Range(pastCell.Offset(0, 15), pastCell.Offset(0, 23)).Value = Range(FutureCell.Offset(0, 1), FutureCell.Offset(0, 9)).Value
                Range(FuturCell.Offset(0, 1), FuturCell.Offset(0, 9)).ClearContents

            End If
        Next FuturCell
    Next pastCell
End Sub

这篇关于我一直在代码中获取所需的对象.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆