Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
  • Avatar do usuário
#71933
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
Você não está autorizado a ver ou baixar esse anexo.
#71939
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
mineiro99 agradeceu por isso
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord