本文介绍了通过VBA中的合并单元循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以循环使用。


  • 我有6个合并的单元格,范围 B4:B40 / li>
  • 我需要这6个单元格中的值6次迭代。

  • I have 6 merged cells in the range B4:B40
  • I need the values in these 6 cells 6 iterations only.

推荐答案

上面的答案看起来有你排序。

The above answers look to have you sorted.

如果你不知道合并的单元格在哪里,那么你可以使用下面的例程快速检测他们。

If you don't know where the merged cells are then you can use the following routine to quickly detect them.

当我构建时,我意识到当我开发合并的单元格报告,合并的单元格是 xlBlanks的一部分

When I built Mappit! I realised that when I developed merged cell reporting that merged cells were part of xlBlanks

所以你可以使用代码来立即检测合并的单元格而不是循环通过每个单元格测试 MergedCells 属性为true。

So you can use the code to detect merged cells immediately rather than loop through each cell testing for the MergedCells property being true.

Sub DetectMerged()
Dim rng1 As Range
Dim rng2 As Range
On Error Resume Next
Set rng1 = Intersect(Cells.SpecialCells(xlFormulas), Cells.SpecialCells(xlBlanks))
Set rng2 = Intersect(Cells.SpecialCells(xlConstants), Cells.SpecialCells(xlBlanks))
On Error GoTo 0
If Not rng1 Is Nothing Then MsgBox "Merged formulae cells in " & rng1.Address(0, 0)
If Not rng2 Is Nothing Then MsgBox "Merged constant cells in " & rng2.Address(0, 0)
End Sub

这篇关于通过VBA中的合并单元循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 20:58