質問

オートフィルタはデータを垂直方向にソートしていますが、列を水平にフィルタ処理します。 次の表があると言ってください。

1 2 2 1 2

b e f

b d e f

c d e f

私ができることはオートフィルタを設定し、最初の列に "b"を含む行のみをフィルタリングすることです。私がやりたいことは、 "2"を含む行だけをフィルタリングすることです(この場合、行は2番目の場合は3番目の、そしてこの場合は最後のもの)。

私はこの問題に関するいくつかの情報を見つけました。私が見つけたすべての回答は、ジョブを完了するためにいくつかのマクロを含みますが、それらは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 Specialオプションと一緒にTransposeを使用してデータを変換することを強くお勧めします。 TRANSPOSE()関数を使用してこれを動的に実行できます。

編集:

今すぐ入手しました - あなたは特定の値に基づいて列を非表示にしたいです。実際にはマクロを使用して可能なので、私の最初の回答が正しくありませんでした - それでは申し訳ありません!その周りにいくつかのマクロがあります。そのような解決策を自動フィルタと組み合わせることができます。これはa openoffice.orgからのKing_026によるソリューションフォーラム(テーブル構造にわずかに適応 - 下記参照):

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
.

だから、次の表:

calc1

は、COL1のオートフィルタの後、マクロの後に彼の作業をした後にこのように見えます。

calc

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top