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
#4591
Boa tarde.
Eu criei uma função em VBA que mediante a seleção escolhida nas Colunas de A a D da Sheet 1, faz aparecer na coluna E os textos correspondente a essas opções escolhidas, separados por um espaço.
Só que se eu deixar alguma das colunas (A,B,C ou D)em branco , na coluna E já nao aparece os textos.
Será que é possível apresentar o texto de cada uma das opções na coluna E da Sheet 1, mesmo que uma das colunas (A,B,C ou D) nao esteja preenchida?
Na Coluna B da folha "Tech" estão os textos das tecnologias.

:cry:

Coloco o código do Modulo que criei:
Option Explicit

Function ProcuraMe(d As Range)
Dim g As Object, c As Variant, i As Long, j As Range
Set g = CreateObject("Scripting.Dictionary")
Application.Volatile
On Error GoTo fin
With Sheets("Tech")
Dim lastRow As Long: lastRow = .Range("A" & Rows.Count).End(xlUp).Row
.Range("C2").Value = Application.WorksheetFunction.VLookup(Trim(Sheets("Português").Range("AK" & d.Row).Value), .Range("A1:B" & lastRow), 2, False)
.Range("C3").Value = Application.WorksheetFunction.VLookup(Trim(Sheets("Português").Range("AL" & d.Row).Value), .Range("A1:B" & lastRow), 2, False)
.Range("C4").Value = Application.WorksheetFunction.VLookup(Trim(Sheets("Português").Range("AM" & d.Row).Value), .Range("A1:B" & lastRow), 2, False)
.Range("C5").Value = Application.WorksheetFunction.VLookup(Trim(Sheets("Português").Range("AN" & d.Row).Value), .Range("A1:B" & lastRow), 2, False)
.Range("C6").Value = Application.WorksheetFunction.VLookup(Trim(Sheets("Português").Range("AO" & d.Row).Value), .Range("A1:B" & lastRow), 2, False)

lastRow = .Cells(Rows.Count, 3).End(xlUp).Row
c = .Range("C1:C" & lastRow)
For i = 1 To UBound(c, 1)
g(c(i, 1)) = 1
Next i
.Range("C1:C" & lastRow).ClearContents
lastRow = .Cells(Rows.Count, 4).End(xlUp).Row
.Range("D1:D" & lastRow).ClearContents
.Range("D1").Resize(g.Count) = Application.Transpose(g.keys)
lastRow = .Cells(Rows.Count, 4).End(xlUp).Row
Set c = .Range("D1:D" & lastRow)
For Each j In c
ProcuraMe = ProcuraMe & " " & j
Next j
Sheets("Português").Range("AR" & d.Row).Value = Trim(ProcuraMe)
.Range("D1:D" & lastRow).ClearContents
End With
Exit Function
fin: MsgBox "Nao encontrado! " & vbNewLine & "Pode ser que algumas das colunas(AK:AO), estejam vazias ou " & vbNewLine & _
"Algum dado das colunas (AK:AO) nao estejam contidas na aba [Tech]", 64, "Atencao": Exit Function
End Function



Obrigado.
#4592
Por que você não usa
Código: Selecionar todos
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
para fazer isso ao invés de criar uma função?

Caso ache interessante meu conselho, faça um teste com Application.Intersect para verificar se a região alterada é a que irá fazer a alteração nas outras regiões da planilha.
#4593
Mas eu fiz isso na Sheet 1:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lastRow As Long: lastRow = Range("AK" & Rows.Count).End(xlUp).Row
If Not Intersect(Target, Range("AK7:AO" & lastRow)) Is Nothing Then
ProcuraMe Target
End If
End Sub

E coloquei o codigo do post anterior no module 1.
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