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
  • Avatar do usuário
Por rafael84
Posts
#16111
Pessoal, estou quebrando a cabeça e não consigo resolver....
Tenho dois arquivos arquivo1.xslx e arquivo2.xlsx, os dois arquivos tem as colunas nome e cargos (A e B). Eu preciso comparar o arquivo1 com o arquivo2 e onde os nomes forem iguais, colocar o cargo no arquivo2. Não sei como abrir no macro o arquivo2 e fazer a comparacao usando o for. Alguem tem exemplo pra eu me basear?

Obrigado.
Avatar do usuário
Por alexandrevba
Avatar
#16173
Bom dia!!

Visto que você não detalhou....
Foi considerado a seguinte situação...
1.Ambos arquivos já estão salvos em um local qualquer.
2.Ambos arquivos estão abertos.
3.Favor adaptar os nomes das guias e nomes e extensões dos arquivos (Aquivo2.xlsm) no meu caso eu usei xlsm.
Código: Selecionar todos
Sub AleVBA_3228()
    Dim wsFO As String
    Dim wsFT As Worksheet
    Set wsFT = Workbooks("Aquivo2.xlsm").Sheets("NomeGuiaArq2")
    With Workbooks("Aquivo1.xlsm").Sheets("NomeGuiaArq1")
        wsFO = "'" & .Parent.Path & "\[" & .Parent.Name & "]" & .Name & "'!"
    End With
    With wsFT.Cells(1).CurrentRegion
        With .Columns("B").Offset(1).Resize(.Rows.Count - 1)
            .Formula = "=IFERROR(VLOOKUP(A2," & wsFO & "A:B,2,false),"""")"
            .Value = .Value
        End With
    End With
End Sub

Att
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