autopilter正在垂直排序数据,但我想水平过滤行。 让我们说我有下表:

1 2 2 1 2

b a e f

b d e f f

c d e f f f f

我可以做的是设置一个自动滤波器并仅在第一列中仅筛选包含“b”的行。我想做的是只过滤包含“2”的行(在这种情况下,行是秒,第三,在这种情况下最后一个)。

我已经找到了一些关于这件事的信息。我发现的所有答案都包含一些宏来完成作业,但它们是为MS Excel编写的,并且与OpenOffice 不兼容

例如,此宏应该获取过滤的行,但不在OpenOffice Calc中工作:

Option Explicit

Sub horizontal_filter()
'Erik Van Geit
'060910

Dim LC As Integer           'Last Column
Dim R As Long
Dim i As Integer
Dim FilterValue As String

Const FilterColumn = 1      '1 is most logical value but you may change this

R = ActiveCell.Row
LC = Cells(R, Columns.Count).End(xlToLeft).Column

FilterValue = Cells(R, FilterColumn)

Application.ScreenUpdating = False

'to filter starting after FilterColumn
For i = FilterColumn + 1 To LC
'to filter all columns even before the filtercolumn
'For i = 1 To LC
    If i <> FilterColumn Then
    Columns(i).Hidden = Cells(R, i) <> FilterValue
    End If
Next i

Application.ScreenUpdating = True

End Sub
.

任何帮助非常感谢!

有帮助吗?

解决方案

你不能在合理的费用的假设下。转换数据时,它更容易,以便行收到列,反之亦然。因此,我强烈建议使用Paste SpecialTranspose选项一起转换数据。您甚至可以通过使用TRANSPOSE()函数动态执行此操作。

编辑:

现在我有它 - 你想要隐藏列基于一定的值。事实上,这是可以使用宏的,所以我的第一个答案是不正确的 - 抱歉!有一些宏,这将为您做到这一点。您可以使用自动筛选器组合这样一个解决方案。这是一个 solution by nodoffice.org论坛(略微适应表格结构 - 见下文):

REM  *****  BASIC  *****
sub hide
   rem ----------------------------------------------------------------------
   rem define variables
   dim document   as object
   dim dispatcher as object
   rem ----------------------------------------------------------------------
   rem get access to the document
   document   = ThisComponent.CurrentController.Frame
   dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

   rem get the current column
   nCol = ThisComponent.CurrentSelection.CellAddress.Column

   rem set the properties for moving right
   dim args2(1) as new com.sun.star.beans.PropertyValue
   args2(0).Name = "By"
   args2(0).Value = 1
   args2(1).Name = "Sel"
   args2(1).Value = false

   rem make thecurrent column counter
   dim cCol as integer
   CCol = 0

   rem goto the first column
   dim args1(0) as new com.sun.star.beans.PropertyValue
   args1(0).Name = "ToPoint"
   args1(0).Value = "$A$2"

   dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())

   rem loop until you get back to the selected cell
    Do Until cCol > nCol

    rem hide if the cell value is 1
        if ThisComponent.CurrentSelection.string <> "" and ThisComponent.CurrentSelection.value = 1 then

            rem ----------------------------------------------------------------------
            dispatcher.executeDispatch(document, ".uno:HideColumn", "", 0, Array())

        End if

        rem goto the right nad increment the column counter
        dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args2())
        cCol = cCol + 1

    Loop

End sub
.

所以,下表:

在Col1上的AutoFilter和宏后完成工作后,

将如下所示:

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top