vba 删除格式为表格中的排序图标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22246825/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 02:15:08  来源:igfitidea点击:

Remove sort icon in Format as Table

excelvba

提问by Liyana Natalie

I used "Format as Table" There are sort icons at the top for every column. How do I remove the sort icon from some of the rows and keep the remaining?

我使用了“格式为表格”,每一列的顶部都有排序图标。如何从某些行中删除排序图标并保留其余行?

回答by Pankaj Jaju

You can remove ALL the sort buttons (workaround)

您可以删除所有排序按钮(解决方法)

1- Select the data range

1- 选择数据范围

2- Format as table

2- 格式化为表格

3- Right click --> Select Table--> Convert to Range

3- 右键单击​​ --> 选择Table-->Convert to Range

This will keep the formatting, but the sort buttons would be removed.

这将保留格式,但排序按钮将被删除。



Alternatively, if you want to keep some of the sort icons, then you have to use VBA

或者,如果你想保留一些排序图标,那么你必须使用 VBA

1- Suppose this is your formatted table

1-假设这是您的格式化表格

enter image description here

在此处输入图片说明

2- Write this function

2- 编写这个函数

Sub RemoveSortArrows()
    Application.ScreenUpdating = False

    For Each col In Range("A1:J1")
        If Not (col.Column = 1 Or col.Column = 4) Then
            col.AutoFilter Field:=col.Column, Visibledropdown:=False
        End If
    Next

    Application.ScreenUpdating = True
End Sub

3- This should be the result

3-这应该是结果

enter image description here

在此处输入图片说明

回答by Kapol

I'd like to add one thing to Pankaj'sanswer. Instead of hard typing the header range, you can use

我想在Pankaj 的回答中添加一件事。您可以使用,而不是硬输入标题范围

Dim myTable As ListObject

Set myTable = ActiveSheet.ListObjects([the name of your table goes in here])

And in the Forloop signature you type

For循环签名中你输入

For Each Cell In myTable.HeaderRowRange