Views

...

Important:

Quaisquer soluções e/ou desenvolvimento de aplicações pessoais, ou da empresa, que não constem neste Blog podem ser tratados como consultoria freelance.

E-mails

Deixe seu e-mail para receber atualizações...

eBook Promo

VBA Excel - Verificando se a célula ativa está em uma tabela ou lista



Muitas vezes antes de executar outros comandos e funções, queremos garantir que a célula ativa esteja em uma tabela ou lista. 

Os seguintes testes de código para essa condição exibe uma caixa de mensagem com os resultados.

Sub ActiveCellIsInTable()
    Dim ActiveCellInTable As Boolean
    Dim ACell As Range

    'Set a reference to the ActiveCell named ACell. You can always use
    'ACell now to point to this cell, no matter where you are in the workbook.
    Set ACell = ActiveCell

    'Test whether ACell is in a table.
    On Error Resume Next
    Let ActiveCellInTable = (ACell.ListObject.Name <> "")
    On Error GoTo 0

    If ActiveCellInTable = True Then
        MsgBox "Esta célula (ActiveCell) é parte da tabela."
    Else
        MsgBox "Esta célula (ActiveCell) não é parte da tabela."
    End If
End Sub

Se a célula ativa estiver numa tabela, podemos usar a seguinte declaração para apontar para a tabela inteira.

ACell.ListObject.Range

Você pode usar a seguinte instrução para fazer referência a uma tabela sem cabeçalho.

ACell.ListObject.DataBodyRange


Tags: Excel, VBA, cell, activecell, table, list




Inline image 1

eBooks VBA na AMAZOM.com.br

LinkWithinBrazilVBAExcelSpecialist

Related Posts Plugin for WordPress, Blogger...

Vitrine