gpt4 book ai didi

Excel VBA获取合并单元格的内容

转载 作者:行者123 更新时间:2023-12-04 20:53:17 24 4
gpt4 key购买 nike

我有这张单子(monad)。

enter image description here

在 VBA 中,我得到第 8 行列 AV、AU、AW 的内容,如下所示。

.Cells(row_level - 1, col_comment)

第 7 行是合并的单元格。如果列是 AV、AU 或 AW,我想获取 AV 的内容。棘手的部分是并不总是有三个合并的列。可能有 2 到 7 个。

最佳答案

尝试,

Sub test()
Dim rngDB As Range, rng As Range
Dim vR()
Dim i As Long, n As Long, j As Integer

Set rngDB = Range("au8", Range("au" & Rows.Count).End(xlUp))

For Each rng In rngDB
If rng.MergeCells Then
If rng.Address = rng.MergeArea.Range("a1").Address Then
n = n + 1
ReDim Preserve vR(1 To 3, 1 To n)
For j = 1 To 3
vR(j, n) = rng(1, j)
Next j
End If
Else
n = n + 1
ReDim Preserve vR(1 To 3, 1 To n)
For j = 1 To 3
vR(j, n) = rng(1, j)
Next j
End If
Next rng
Sheets.Add
Range("a1").Resize(n, 3) = WorksheetFunction.Transpose(vR)
End Sub

关于Excel VBA获取合并单元格的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53137634/

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