Pergunta

O filtro automático está classificando os dados verticalmente, mas quero filtrar as linhas horizontalmente.Digamos que eu tenha a seguinte tabela:

1 2 2 1 2

B A E F F

B D E F F

C D E F F

O que posso fazer é definir um filtro automático e filtrar apenas as linhas que contêm “B” na primeira coluna.O que eu gostaria de fazer é filtrar apenas as linhas que contenham "2" (neste caso as linhas são a segunda, a terceira e a última neste caso).

Encontrei algumas informações sobre esse assunto.Todas as respostas que encontrei contêm algumas macros para realizar o trabalho, mas foram escritas para MS Excel e não são compatíveis com OpenOffice

Por exemplo, esta macro deve filtrar as linhas, mas não está funcionando no 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

Qualquer ajuda é muito apreciada!

Foi útil?

Solução

Você não pode, sob a suposição de despesas razoáveis.É muito mais fácil transformar seus dados para que as linhas recebam colunas e vice-versa.Então, eu recomendo fortemente transformar os dados usando Paste Special junto com o Transpose opção.Você pode até fazer isso dinamicamente usando o TRANSPOSE() função.

EDITAR:

Agora eu entendi - você quer ocultar colunas com base em um determinado valor.Na verdade, isso é possível usando uma macro, então minha primeira resposta estava incorreta - desculpe por isso!Existem algumas macros que farão isso por você.Você pode combinar essa solução com um filtro automático.Aqui está um solução por king_026 dos fóruns do OpenOffice.org (ligeiramente adaptado à estrutura da tabela - veja abaixo):

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

Então, a seguinte tabela:

calc1

ficará assim depois do Autofiltro na Col1 e depois que a macro fez seu trabalho:

calc

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top