marco6325
05-28-2018, 02:48 AM
I want to create a Macro that I have not been able to find, I explain the desired operation:
The file has the following Sheets:
Sheets "Origin"
DNI"sheets (One sheet for each ID number)
Now in the Origin Sheet in column "A" has the numbers of "DNI",which could be repeated in several rows, since there is varied information foreach DNI, such as visited countries, what I want is for the macro to evaluate the LeafOrigin and copy the countries visited and price of the passage on the sheet with the name of the DNI from cell B39 for the country and c39 for the priceof the passage.
Illustratively the sheet "origin" would be something like this:
Column A Column B Column C
Row 1 DNI #123 Peru 2,000 Pesos
Row2 DNI # 456 Colombia 1,000 Pesos
Row3 DNI # 123 Argentina 3,000 Pesos
The sheet called 123 would have as a result
Column A Column B
Row 39 Peru 2,000 Pesos
Fila40 Argentina 3,000Pesos
The sheet called 456 would have as a result
Column A Column B
Row 39 Colombia 1,000 Pesos
NOTE:they are not only Country and Price, I would have several columns whose information I wanted to pass to the DNI sheet, place only 2 as an example,
Thank you in advance for your support of the area's super experts!
I just Tried wth this:
'Definir objetos a utilizar
Dim wsOrigen As Excel.Worksheet, _
wsDestino As Excel.Worksheet, _
rngOrigen As Excel.Range, _
rngDestino As Excel.Range
'Indicar las hojas de origen y destino
Set wsOrigen = Worksheets("Origen")
Set wsDestino = Worksheets("Destino")
'Indicar la celda de origen y destino
Const celdaOrigen = "Q2"
Const celdaDestino = "C39"
'Inicializar los rangos de origen y destino
Set rngOrigen = wsOrigen.Range(celdaOrigen)
Set rngDestino = wsDestino.Range(celdaDestino)
'Seleccionar rango de celdas origen
Sheets("Origen").Select
rngOrigen.Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
'Pegar datos en celda destino
rngDestino.PasteSpecial xlPasteValues
Application.CutCopyMode = False
End Sub
The file has the following Sheets:
Sheets "Origin"
DNI"sheets (One sheet for each ID number)
Now in the Origin Sheet in column "A" has the numbers of "DNI",which could be repeated in several rows, since there is varied information foreach DNI, such as visited countries, what I want is for the macro to evaluate the LeafOrigin and copy the countries visited and price of the passage on the sheet with the name of the DNI from cell B39 for the country and c39 for the priceof the passage.
Illustratively the sheet "origin" would be something like this:
Column A Column B Column C
Row 1 DNI #123 Peru 2,000 Pesos
Row2 DNI # 456 Colombia 1,000 Pesos
Row3 DNI # 123 Argentina 3,000 Pesos
The sheet called 123 would have as a result
Column A Column B
Row 39 Peru 2,000 Pesos
Fila40 Argentina 3,000Pesos
The sheet called 456 would have as a result
Column A Column B
Row 39 Colombia 1,000 Pesos
NOTE:they are not only Country and Price, I would have several columns whose information I wanted to pass to the DNI sheet, place only 2 as an example,
Thank you in advance for your support of the area's super experts!
I just Tried wth this:
'Definir objetos a utilizar
Dim wsOrigen As Excel.Worksheet, _
wsDestino As Excel.Worksheet, _
rngOrigen As Excel.Range, _
rngDestino As Excel.Range
'Indicar las hojas de origen y destino
Set wsOrigen = Worksheets("Origen")
Set wsDestino = Worksheets("Destino")
'Indicar la celda de origen y destino
Const celdaOrigen = "Q2"
Const celdaDestino = "C39"
'Inicializar los rangos de origen y destino
Set rngOrigen = wsOrigen.Range(celdaOrigen)
Set rngDestino = wsDestino.Range(celdaDestino)
'Seleccionar rango de celdas origen
Sheets("Origen").Select
rngOrigen.Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
'Pegar datos en celda destino
rngDestino.PasteSpecial xlPasteValues
Application.CutCopyMode = False
End Sub