Created
May 5, 2018 18:01
-
-
Save juliofruta/9acde4772c244bec24d807d101a6bcb6 to your computer and use it in GitHub Desktop.
A macro that helps you build repeated lists of fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Macro() | |
' | |
' Macro Macro | |
' Para usar: 1. Cambia el nombre de la página a Input. 2. Selecciona las filas que quieres transformar. 3. Selecciona los campos que quieres mostrar | |
' | |
' Acceso directo: CTRL+m | |
Dim filasATransformar As Range | |
Set filasATransformar = Application.InputBox("Selecciona un rango de filas a transformar", Type:=8) | |
Dim columnasAUtilizar As Range | |
Set columnasAUtilizar = Application.InputBox("Selecciona un rango de columnas a utilizar", Type:=8) | |
Dim WS As Worksheet | |
Set WS = Sheets.Add | |
Sheets.Add.Name = "Output" | |
Set sheetOrigin = ThisWorkbook.Sheets("Input") | |
Set sheetResult = ThisWorkbook.Sheets("Output") | |
Dim fila As Integer | |
fila = 1 | |
Dim cell As Range | |
For Each cell In filasATransformar | |
Dim columna As Range | |
For Each columna In columnasAUtilizar | |
columna.Copy | |
Range(sheetResult.Cells(fila, 1), sheetResult.Cells(fila, 1)).PasteSpecial | |
Dim coordenadaDeColumna As Integer | |
coordenadaDeColumna = columna.Column | |
Dim coordenadaDeFila As Integer | |
coordenadaDeFila = cell.Row | |
sheetOrigin.Cells(coordenadaDeFila, coordenadaDeColumna).Copy | |
Range(sheetResult.Cells(fila, 2), sheetResult.Cells(fila, 2)).PasteSpecial | |
fila = fila + 1 | |
Next columna | |
Next cell | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment