- 22 Out 2015 às 11:14
#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.
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.
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.
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.