Gostaria que alguém sugerisse a codificação em VBA necessária para converter esses dados. Essencialmente B2 e B3 haverá várias células como essas, mesmo com mais ";" e números depois. O T e eu não vamos mudar, mas alguns nem sempre têm T ou I, são apenas um único número.
A saída final precisa ser B12:C37
Basicamente, quero uma lista de números com os dados correspondentes próximos a ela. Portanto, 1T4 deve ser 1,2,3,4 em 4 células (em 1 coluna), 1T5I2 é 1,3,5 (onde I2 = 2 números inteiros separados). T e eu nem sempre precisamos estar lá. se T estiver lá, eu não preciso estar lá. Se T estiver lá, I estará sempre atrás.
Se a célula mostrar 25;45;56;79, então 25 vai para uma célula, 45 para outra, etc.
As únicas combinações que você verá são: 1;1T2;1T5I2. E os números serão inteiros positivos potencialmente até 10.000.
Pode haver B2 a B20, e os pontos e vírgulas podem ser milhares deles.....
Estou pensando em um loop para olhar cada caractere e se for um número, então faça uma string entre os números até que seja quebrada por um T,I ou ; - No entanto, estou preso.
Imagem do que procuro no Excel:
Responder1
Macro3 é vários pontos e vírgulas em uma célula
Macro2 é para múltiplas entradas de B2 a B20
Copie e cole esta macro com a planilha e execute-a:
Sub Macro3()
'
Dim Txt1, TxtL, Str(), Fruit, Txt As String
Dim x, n, Ff, Tt, Ii, r, i, L, Lx, ix As Integer
r = 12
For x = 2 To 20
Txt1 = Range("B" & x).Value
TxtL = Txt1
Fruit = Range("A" & x).Value
L = Len(Txt1) - Len(Replace(Txt1, ";", ""))
ReDim Str(L)
If Txt1 = "" Then Exit For
For Lx = 0 To L
ix = InStr(1, TxtL, ";")
If ix = 0 Then ix = Len(Txt1) + 1
Str(Lx) = Left(TxtL, ix - 1)
TxtL = Mid(TxtL, ix + 1, Len(Txt1))
Next Lx
For n = 0 To L
Txt = Str(n)
Ff = 0: Tt = 0: Ii = 1
Ff = Val(Txt)
If InStr(1, Txt, "T") > 0 Then Tt = Val(Mid(Txt, InStr(1, Txt, "T") + 1, Len(Txt))) Else Tt = Ff
If InStr(1, Txt, "I") > 0 Then Ii = Val(Mid(Txt, InStr(1, Txt, "I") + 1, Len(Txt))) Else Ii = 1
For i = Ff To Tt Step Ii
Range("D" & r).Value = i
Range("E" & r).Value = Fruit
r = r + 1
Next i
Next n
Next x
MsgBox "done"
End Sub
Sub Macro2()
'
Dim Txt1, Str(4), Fruit, Txt As String
Dim x, n, Ff, Tt, Ii, r, i As Integer
r = 12
For x = 2 To 20
Txt1 = Range("B" & x).Value
Fruit = Range("A" & x).Value
If Txt1 = "" Then Exit For
Str(0) = Left(Txt1, InStr(1, Txt1, ";") - 1)
Str(1) = Mid(Txt1, InStr(1, Txt1, ";") + 1, Len(Txt1))
For n = 0 To 1
Txt = Str(n)
Ff = 0: Tt = 0: Ii = 1
Ff = Val(Txt)
If InStr(1, Txt, "T") > 0 Then Tt = Val(Mid(Txt, InStr(1, Txt, "T") + 1, Len(Txt))) Else Tt = Ff
If InStr(1, Txt, "I") > 0 Then Ii = Val(Mid(Txt, InStr(1, Txt, "I") + 1, Len(Txt))) Else Ii = 1
For i = Ff To Tt Step Ii
Range("D" & r).Value = i
Range("E" & r).Value = Fruit
r = r + 1
Next i
Next n
Next x
MsgBox "done"
End Sub
Sub Macro1()
'
Dim Txt1, Txt2, Str(4), Txt As String
Dim n, Ff, Tt, Ii, r, i As Integer
Txt1 = Range("B2").Value
Txt2 = Range("B3").Value
Str(0) = Left(Txt1, InStr(1, Txt1, ";") - 1)
Str(1) = Mid(Txt1, InStr(1, Txt1, ";") + 1, Len(Txt1))
Str(2) = Left(Txt2, InStr(1, Txt2, ";") - 1)
Str(3) = Mid(Txt2, InStr(1, Txt2, ";") + 1, Len(Txt2))
r = 12
For n = 0 To 3
Txt = Str(n)
Ff = 0: Tt = 0: Ii = 1
Ff = Val(Txt)
If InStr(1, Txt, "T") > 0 Then Tt = Val(Mid(Txt, InStr(1, Txt, "T") + 1, Len(Txt))) Else Tt = Ff
If InStr(1, Txt, "I") > 0 Then Ii = Val(Mid(Txt, InStr(1, Txt, "I") + 1, Len(Txt))) Else Ii = 1
For i = Ff To Tt Step Ii
Range("B" & r).Value = i
If i >= 1 And i <= 10 Then Range("C" & r).Value = "Apple"
If i > 10 Then Range("C" & r).Value = "Mango"
r = r + 1
Next i
Next n
MsgBox "done"
End Sub