Página 1 de 1

Identificar e nomear a ultima célula de tabelas

Enviado: 02 Ago 2022 às 13:46
por mineiro99
Boa tarde!

Tenho uma planilha com várias tabelas com número de linhas variadas. Gostaria de uma macro que identificasse a última linha de cada tabela e inserisse a palavra fim.

Tabela 1
aaa
aaa
aaa
FIM

Tabela 2
bbb
bbb
bbb
bbb
FIM

Tabela 3
ccc
ccc
FIM

Re: Identificar e nomear a ultima célula de tabelas

Enviado: 03 Ago 2022 às 07:23
por AfonsoMira
Boas,
Veja se é isto que pretende:
Código: Selecionar todos
Sub InserirFim()

Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws As Worksheet: Set ws = wb.ActiveSheet

Dim ultimaLinha As Long
ultimaLinha = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row + 1

Dim i As Long

For i = 1 To ultimaLinha

If IsEmpty(ws.Cells(i, 2)) Then 'Se Vazio
    If Not IsEmpty(ws.Cells(i - 1, 2)) Then
        If ws.Cells(i - 1, 2) <> "FIM" Then
            ws.Cells(i, 2) = "FIM"
        End If
    End If
End If

Next i

End Sub