gpt4 book ai didi

excel - VBA向上/向下 move 选定范围(有偏移?)

转载 作者:行者123 更新时间:2023-12-04 21:57:41 25 4
gpt4 key购买 nike

我正在构建一个工具,其中用户选择的单元格内容用箭头形状 move 。

下面的代码非常适合向下 move 一组或多组相邻单元格。
但是,反转代码似乎很棘手(偏移量 +1 不起作用:-?)

任何想法?
谢谢,
奥古斯丁

Sub Move_Up()
Selection.Cut
Selection.Offset(-1, 0).Select
Selection.Insert Shift:=xlDown
End Sub

最佳答案

假设要 move 单元格并且被覆盖的单元格只是 move 到曾经 move 过的单元格,代码可能如下:

Sub MoveUp()
Selection.Rows(Selection.Rows.count + 1).Insert Shift:=xlDown
Selection.Rows(1).Offset(-1).Cut Selection.Rows(Selection.Rows.count + 1)
Selection.Rows(1).Offset(-1).Delete Shift:=xlUp
Selection.Offset(-1).Select
End Sub

Sub MoveDown()
Selection.Rows(1).Insert Shift:=xlDown
Selection.Rows(Selection.Rows.count).Offset(2).Cut Selection.Rows(1)
Selection.Rows(Selection.Rows.count).Offset(2).Delete Shift:=xlUp
Selection.Offset(1).Select
End Sub

关于excel - VBA向上/向下 move 选定范围(有偏移?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41408969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com