Excel检查行是否属于组 [英] Excel checking if row is part of a group

查看:40
本文介绍了Excel检查行是否属于组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个宏,以在一个很大的excel文档中创建一些订单.对特定选择进行几次操作后,我想检查该选定范围内是否有分组的行,如果是,则需要将其取消分组.取消所有行的分组之后(可以是该范围内的一些单独的组,可以是一个大组,甚至根本不分组),需要将它们全部分组在一起.下面的代码部分从选择特定范围开始,我认为解决方案是遍历该范围并检查所有行是否属于组,如果是,则需要将其取消分组.但是不知道如何将这个概念转化为有效的代码:)另外,下面提供了取消分组/分组操作之前的范围示例.

I'm working on a macro to create some order in a very large excel doc. After a few operations on a specific selection, I would like to check if there are rows in that selected range that are grouped, and if so, they need to be ungrouped. After ungrouping all the rows (could be some seperate groups in the range, could be one big group or not even grouped at all), they need to be grouped all together. The part of the code below starts with selecting the specific range, I think the solution is looping through the range and checking all the rows if they are part of a group, and if so, they would be needed to be ungrouped. But Don't know how to translate this concept into a working code :) Also, an example of a range before the ungrouping/grouping operation is included below.

Range(Cells(Rstart, "H"), Cells(Rend, "H")).Select
Selection.Rows.Ungroup
Selection.Rows.Group

推荐答案

目前尚不清楚您要做什么.无论如何,我想这会为您提供帮助.

It is not quite clear what you mean to do. At any rate, I guess this will help you.

  1. 选择完整的行.

Dim rng As Range
Set rng = Selection
rng.EntireRow.Select

  • 取消分组(例如,此处).也许您可以使用 Outlinelevel 来确定是否对行进行了分组.这将取消对前20个行的分组.

  • Ungrouping (e.g., here). Maybe you can use the Outlinelevel to determine whether a row is grouped. This will ungroup rows in the first 20.

    Sub x()
        Dim lngRow As Long
        For lngRow = 1 To 20
            If ActiveSheet.Rows(lngRow).OutlineLevel > 1 Then
                Do While ActiveSheet.Rows(lngRow).OutlineLevel > 1
                    ActiveSheet.Rows(lngRow).Ungroup
                Loop
            End If
        Next
    End Sub
    

  • 分组.您已经知道如何执行此操作.

  • Grouping. You already know how to do this.

    这篇关于Excel检查行是否属于组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆