Domanda

L'autofiltro automatico sta ordinando i dati verticalmente, ma voglio filtrare le righe orizzontalmente. Diciamo che ho la seguente tabella:

1 2 2 1 2

B A E F F

B D E F F

c d e f f

Cosa posso fare è impostare un autofiltro automatico e filtrare solo le righe contenenti "B" nella prima colonna.Quello che vorrei fare è filtrare solo le righe che contengono "2" (in questo caso le righe sono seconde, terzi e l'ultima in questo caso).

Ho trovato alcune informazioni su questa questione.Tutte le risposte che ho trovato stanno contenenti alcune macro per fare il lavoro, ma sono stati scritti per MS Excel, e non sono compatibili con OpenOffice

Ad esempio, questa macro dovrebbe ottenere le righe filtrate, ma non funziona in 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
.

Qualsiasi aiuto è molto apprezzato!

È stato utile?

Soluzione

Non è possibile, sotto l'assunzione di spese ragionevoli. È molto più facile solo trasformare i tuoi dati in modo che le righe ottengano colonne e viceversa. Quindi, consiglio vivamente la trasformazione dei dati utilizzando Paste Special insieme all'opzione Transpose. Potresti anche farlo dinamicamente utilizzando la funzione TRANSPOSE().

Modifica:

Ora ho capito - vuoi Nascondi colonne in base a un determinato valore. Questo è possibile usando una macro infatti, quindi la mia prima risposta è stata errata - mi dispiace per quello! Ci sono alcuni macro intorno a ciò farà questo per te. È possibile combinare una soluzione del genere con un filtro automatico. Ecco un Soluzione di King_026 da The OpenOffice.org Forum (leggermente adatto alla struttura della tabella - Vedi sotto):

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
.

Allora, la seguente tabella:

calc1

Sembrerà questo dopo l'autofiltro automatico su Col1 e dopo la macro ha fatto il suo lavoro:

calc

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top