excel - 如何防止在 Do While 循环中合并的单元格将我选定的单元格从 VBA 中的一列移动到另一列?
问题描述
我从银行收到 excel 文件,其中包含我在特定列中需要的信息。所以我想遍历特定的列并获取这些单元格的值。假设我选择 B 列。我从 B1 开始并遍历列单元格。但是,一旦我到达一个合并的单元格,其中有很多,当我试图移过它时,合并的单元格会让我离开 B 列。我正在使用 Offset(1, 0) 向下列。
'Here is a quick example of how the selected cell will move
'I'm using an index to move down 15 cells
'Merge cell A2 and B2 before running the macro
Sub test()
Dim index As Integer
index = 0
Range("B1").Select
Do While index < 15
Selection.Offset(1, 0).Select
index = index + 1
Loop
End Sub
选择从 B1 移动到 B2,与 A2 合并,然后继续到 A3 而不是 B3。
解决方案
推荐阅读
- javascript - 将我的 canvasjs 图表转换为 chart.js 图表
- java - 未调用handleFrame
- java - Netbeans SLF4J:类路径包含多个 SLF4J 绑定
- rspec - Rspec - “所有示例都被过滤掉了”
- javascript - 我无法导出在我的一个反应组件中创建的数组
- javascript - 在 try catch 块中放置和 if 条件的首选方法是什么?
- cmake - GitHub Actions CI 中缓存的命中率 0.00 %
- flutter - 显示 SnackBar() 小部件时出现“英雄小部件不能是另一个英雄小部件的后代”问题
- qt - 无法通过触摸选择 qcombobox 项目
- jquery - 单词顺序的Jquery自动完成问题