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.
Por IgorAM
#61843
Preciso de uma rotina que leia valores e uma planilha, encontre-os em outra e depois pegue a data.
Fiz o seguinte código e estou com alguns problemas

Dim W As Worksheet
Dim Y As Worksheet
Set W = Sheets("Plan4")
Set Y = Sheets("Plan3")
W.Range("B2").Select
For i = A To C
For j = 4 To 2
Do While ActiveCell = ""
ActiveCell.Value = Application.WorksheetFunction.VLookup(W.Range("A" & ActiveCell.Row).Value, Y.Range(i & "2:D4"), j, 0)
ActiveCell.Offset(1, 0).Select
Loop
Next
Next

A planilha Y onde estão os valores que devem ser procurados possui varias colunas com esses valores, por isso a coluna deve variar. Se eu fosse colocar as formulas nas células precisaria seguir o seguinte padrão

VLookup(W.Range("A" & ActiveCell.Row).Value, Y.Range("A2:D4"), 4, 0)

Depois mudar para
VLookup(W.Range("A" & ActiveCell.Row).Value, Y.Range("B2:D4"), 3, 0)

Depois mudar para
VLookup(W.Range("A" & ActiveCell.Row).Value, Y.Range("C2:D4"), 2, 0)

Como posso fazer isso? Pensei em usar o For como vocês podem ver, mas não deu muito certo. Em anexo está a planilha, caso queiram testar.
Teste Cargas.xlsx.xlsm
Você não está autorizado a ver ou baixar esse anexo.
Por osvaldomp
#61846
Código: Selecionar todos
Sub BuscaCOD()
 Dim c As Long, d As Range
  With Sheets("Plan4")
   For c = 2 To .Cells(Rows.Count, 1).End(3).Row
    Set d = Sheets("Plan3").[A:C].Find(.Cells(c, 1))
    If Not d Is Nothing Then .Cells(c, 2) = Sheets("Plan3").Cells(d.Row, 4)
   Next c
  End With
End Sub
kiko, JCabral 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