-1
I need to concatenate with VBA the texts contained in two columns in Excel spreadsheet, joining them in another column, but performing this procedure for six tabs.
The data of columns B and H need to be concatenated with a space between them in column A. Adapting the codes I found I was able to perform the procedure to only one tab, but as I don’t have the necessary knowledge of repeating structures, I’m not able to perform in the others. It is worth mentioning that the worksheet contains other tabs besides the six, and in these others I do not intend to concatenate, because it has a different layout than the others, which prevents to perform the procedure by workbook.
The tabs where I wish the concatenation are called so:
SEM_0_EQUIP, SEM_1_EQUIP, SEM_2_EQUIP, SEM_0_LOCAIS, SEM_1_LOCAIS, SEM_2_LOCAIS
The existing and adapted code was thus:
Sub Concatena_dados_de_duas_colunas()
Dim vaColuna2 As Variant, vaColuna8 As Variant, vaDados() As Variant 'variavel para as colunas 2, 8 e dados
Dim wsPlan As Worksheet
Dim rnColuna2 As Range, rnColuna8 As Range, rnDados As Range 'variavel para as colunas 2 e 8
Dim iNumero As Long
Set wsPlan = Worksheets("SEM_0_EQUIP") 'A variavel é igual a planilha desejada
Set rnColuna2 = wsPlan.Range("B3", Range("B1048576").End(xlUp)) 'setada a coluna 2 com o range possivel
Set rnColuna8 = wsPlan.Range("H3", Range("H1048576").End(xlUp)) 'setada a coluna 8 com o range possivel
vaColuna2 = rnColuna2.Value
vaColuna8 = rnColuna8.Value
ReDim vaDados(1 To UBound(vaColuna2))
For iNumero = 1 To UBound(vaColuna2)
vaDados(iNumero) = vaColuna2(iNumero, 1) & " " & vaColuna8(iNumero, 1)
Next iNumero
Set rnDados = wsPlan.Range("A3", Range("A" & UBound(vaColuna2) + 2)) 'o mais dois no final é para fazer com que os dados comecem na linha 3
rnDados.Value = Application.Transpose(vaDados)
vaColuna2 = rnColuna2.Value
vaColuna8 = rnColuna8.Value
ReDim vaDados(1 To UBound(vaColuna2))
For iNumero = 1 To UBound(vaColuna2)
vaDados(iNumero) = vaColuna2(iNumero, 1) & " " & vaColuna8(iNumero, 1)
Next iNumero
Set rnDados = wsPlan.Range("A3", Range("A" & UBound(vaColuna2) + 2)) 'o mais dois no final é para fazer com que os dados comecem na linha 3
rnDados.Value = Application.Transpose(vaDados)
End Sub
I even believe that there is a possibility to improve this code.