偏移问题从一个WS移动到另一个WS

发布于 2025-02-10 16:03:19 字数 969 浏览 4 评论 0原文

我只是试图将一些信息从列将其移至另一张列的另一列,然后使用偏移将其从我需要开始的行开始。试图不使用.popy或.cut或任何类型。

with ws
    ecol = .cells(7,.columns,count).end(xltoleft).column
    .columns(ecol) = ws2.column("AB").Value2
end with

这有效。只是将其放置在错误的区域。因此,尝试使用偏移量无论如何我都会收到1004错误

   with ws
        ecol = .cells(7, .columns.count).end(xltoleft).column
        .columns(ecol).offset(7,0) = ws2.column("AB").Value2
    end with

错误1004

   with ws
        ecol = .cells(7, .columns.count).end(xltoleft).column
        .columns(ecol).offset(7) = ws2.column("AB").Value2
    end with

错误1004

   with ws
        ecol = .cells(7, .columns.count).end(xltoleft).column
        .columns(7, ecol) = ws2.column("AB").Value2
    end with

我怀疑这是因为它将整个AB列从第1行将整个AB列拉到1MM++,而我无法更改范围。

无论哪种方式,我都希望对此进行一些帮助。我正在WS2上使用动态范围。我认为也许我可以使用.end(XLUP)。行程找到底部行并调整语法,但仍然会遇到相同的错误,或者我只是不知道如何编写它。

任何帮助都将受到赞赏。

I'm simply trying to move some information from a column to another column on another sheet and using offset to get it to start on the row i need it to start on. trying to not use .copy or .cut or any of the sort.

with ws
    ecol = .cells(7,.columns,count).end(xltoleft).column
    .columns(ecol) = ws2.column("AB").Value2
end with

this works. just places it in the wrong area. so trying to use offset in anyway i'm getting 1004 error

   with ws
        ecol = .cells(7, .columns.count).end(xltoleft).column
        .columns(ecol).offset(7,0) = ws2.column("AB").Value2
    end with

Error 1004

   with ws
        ecol = .cells(7, .columns.count).end(xltoleft).column
        .columns(ecol).offset(7) = ws2.column("AB").Value2
    end with

Error 1004

   with ws
        ecol = .cells(7, .columns.count).end(xltoleft).column
        .columns(7, ecol) = ws2.column("AB").Value2
    end with

i suspect maybe it's because it's pulling the entire AB column from row 1 to 1mm+ and i just can't change the range.

either way i'd like some help tweaking this. i'm working with a dynamic range on ws2. i thought maybe i could use .end(xlup).row to find the bottom row and adjust the syntax but still getting the same error or i just don't know how to write it.

any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

永不分离 2025-02-17 16:03:19
 with ws
        ecol = .cells(7, .columns.count).end(xltoleft).column + 1
        endC = ws.cells(ws.rows.count,"AB).end(xlup).row
        .Range(.Cells(7, ecol), .Cells(7 + endC - 1, ecol)) = ws2.Range("AB1:AB" & endC).Value
    end with
 with ws
        ecol = .cells(7, .columns.count).end(xltoleft).column + 1
        endC = ws.cells(ws.rows.count,"AB).end(xlup).row
        .Range(.Cells(7, ecol), .Cells(7 + endC - 1, ecol)) = ws2.Range("AB1:AB" & endC).Value
    end with
情深已缘浅 2025-02-17 16:03:19

我认为您对整个列转移是正确的。此代码将尽可能多地传输列的大部分。

With ws
        ecol = .Cells(7, .Columns.Count).End(xlToLeft).Column + 1
        endRow = .Rows.Count
        .Range(.Cells(7, ecol), .Cells(endRow, ecol)) = ws2.Range("AB1:AB" & endRow - 6).Value
End With

您可能需要将其限制为仅在有数据的地方传输,但这取决于您!

希望它有帮助

I think you were right about the whole column transfer. This code transfers as much of the column as possible.

With ws
        ecol = .Cells(7, .Columns.Count).End(xlToLeft).Column + 1
        endRow = .Rows.Count
        .Range(.Cells(7, ecol), .Cells(endRow, ecol)) = ws2.Range("AB1:AB" & endRow - 6).Value
End With

you may want to restrict this to only transferring where there is data but thats up to you!

hope it helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文