Macro para registros de col a fila con un criterio.
Hola Gonzalez. A ver si me puedes ayudar con esto. Tengo muchos registros con varios campos que cuando los pego en excel quedan todos en una misma columna uno debajo del otro. Dentro de cada registro existen datos (que pueden variar) que quiero que me aparezcan uno en cada linea acompañado de la misma cabecera del registro al que pertenecen.
Por ejemplo de la estructura de un registro que siempre empiezan con GAME:
GAME 1234 CON 1
TERMINAL ID ###
STATUS XYZ
Selections Section
123
456
789
. (Solo para indicarte que podrían haber más)
.
.
GAME ...
------------------------------------
Pues me gustaría que quedara así, en la columna de al lado:
GAME 1234 CPN1 TERMINAL ID #### STATUS XYZ DETAILS 123
GAME 1234 CPN1 TERMINAL ID #### STATUS XYZ DETAILS 456
GAME 1234 CPN1 TERMINAL ID #### STATUS XYZ DETAILS 789
La macro que he estado usando me da este resultado:
GAME 1234 CPN1 TERMINAL ID STATUS XYZ DETAILS 123 456 789
Sub UniendoTexto()
Application.ScreenUpdating = False
Dim texto As String
Dim texto1 As String
Dim ini As Integer, fila As Integer
ini = 1
fila = 1
Range("A1").Select
While ActiveCell <> ""
texto = ActiveCell.Value
If Mid(texto, 1, 4) = "GAME" Then
If ini = 1 Then
ini = ini + 1
Else
Cells(fila, 2).Value = texto1
fila = fila + 1
End If
texto1 = ActiveCell.Value
Else
texto1 = texto1 + " " + ActiveCell.Value
ini = ini + 1
End If
ActiveCell.Offset(1, 0).Select
Wend
Cells(fila, 2).Value = texto1
Application.ScreenUpdating = True
End Sub
Gracias anticipadas y un Saludo.
Por ejemplo de la estructura de un registro que siempre empiezan con GAME:
GAME 1234 CON 1
TERMINAL ID ###
STATUS XYZ
Selections Section
123
456
789
. (Solo para indicarte que podrían haber más)
.
.
GAME ...
------------------------------------
Pues me gustaría que quedara así, en la columna de al lado:
GAME 1234 CPN1 TERMINAL ID #### STATUS XYZ DETAILS 123
GAME 1234 CPN1 TERMINAL ID #### STATUS XYZ DETAILS 456
GAME 1234 CPN1 TERMINAL ID #### STATUS XYZ DETAILS 789
La macro que he estado usando me da este resultado:
GAME 1234 CPN1 TERMINAL ID STATUS XYZ DETAILS 123 456 789
Sub UniendoTexto()
Application.ScreenUpdating = False
Dim texto As String
Dim texto1 As String
Dim ini As Integer, fila As Integer
ini = 1
fila = 1
Range("A1").Select
While ActiveCell <> ""
texto = ActiveCell.Value
If Mid(texto, 1, 4) = "GAME" Then
If ini = 1 Then
ini = ini + 1
Else
Cells(fila, 2).Value = texto1
fila = fila + 1
End If
texto1 = ActiveCell.Value
Else
texto1 = texto1 + " " + ActiveCell.Value
ini = ini + 1
End If
ActiveCell.Offset(1, 0).Select
Wend
Cells(fila, 2).Value = texto1
Application.ScreenUpdating = True
End Sub
Gracias anticipadas y un Saludo.
1 respuesta
Respuesta de Juan Carlos González Chavarría
1