Forum Discussion

Luis_Fernando's avatar
Luis_Fernando
Copper Contributor
Nov 01, 2019

Almacenar horizontalmente (en la misma fila) valores de una variable almacenados verticalmente

Buena tarde:

 

He creado una macro para capturar los valores de una variable que se repite en varias recetas ordenadas verticalmente.


Sub BuscarV()
'
' BuscarV_ord_horiz Macro
'
' Acceso directo: CTRL+o
'
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-1],ReportFormulasRegistradas!R[2]C[+1]:R[16]C[+2],2,1)"
Range("D3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-2],ReportFormulasRegistradas!R[20]C[]:R[34]C[+1],2,1)"
Range("E3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-3],ReportFormulasRegistradas!R[38]C[-1]:R[52]C[],2,1)"
Range("F3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-4],ReportFormulasRegistradas!R[56]C[-2]:R[70]C[-1],2,1)"
Range("G3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-5],ReportFormulasRegistradas!R[74]C[-3]:R[88]C[-2],2,1)"
Range("H3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-6],ReportFormulasRegistradas!R[92]C[-4]:R[106]C[-3],2,1)"
Range("I3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-7],ReportFormulasRegistradas!R[110]C[-5]:R[124]C[-4],2,1)"
Range("J3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-8],ReportFormulasRegistradas!R[128]C[-6]:R[142]C[-5],2,1)"
Range("K3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-9],ReportFormulasRegistradas!R[146]C[-7]:R[160]C[-6],2,1)"
Range("L3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-10],ReportFormulasRegistradas!R[164]C[-8]:R[178]C[-7],2,1)"
Range("M3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-11],ReportFormulasRegistradas!R[182]C[-9]:R[196]C[-8],2,1)"
Range("N3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-12],ReportFormulasRegistradas!R[200]C[-10]:R[214]C[-9],2,1)"
Range("O3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-13],ReportFormulasRegistradas!R[218]C[-11]:R[232]C[-10],2,1)"
Range("P3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-14],ReportFormulasRegistradas!R[236]C[-12]:R[250]C[-11],2,1)"
Range("Q3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-15],ReportFormulasRegistradas!R[254]C[-13]:R[268]C[-12],2,1)"
Range("R3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-16],ReportFormulasRegistradas!R[272]C[-14]:R[286]C[-13],2,1)"
Range("S3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-17],ReportFormulasRegistradas!R[290]C[-15]:R[304]C[-14],2,1)"
Range("T3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-18],ReportFormulasRegistradas!R[308]C[-16]:R[322]C[-15],2,1)"
Range("U3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-19],ReportFormulasRegistradas!R[326]C[-17]:R[340]C[-16],2,1)"
Range("V3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-20],ReportFormulasRegistradas!R[344]C[-18]:R[358]C[-17],2,1)"
Range("W3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-21],ReportFormulasRegistradas!R[362]C[-19]:R[376]C[-18],2,1)"
Range("X3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-22],ReportFormulasRegistradas!R[380]C[-20]:R[394]C[-19],2,1)"
Range("Y3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-23],ReportFormulasRegistradas!R[381]C[-21]:R[412]C[-20],2,1)"
Range("Z3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-24],ReportFormulasRegistradas!R[399]C[-22]:R[430]C[-21],2,1)"
Range("AA3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-25],ReportFormulasRegistradas!R[417]C[-23]:R[448]C[-22],2,1)"
Range("AB3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-26],ReportFormulasRegistradas!R[435]C[-24]:R[466]C[-23],2,1)"
Range("AC3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-27],ReportFormulasRegistradas!R[453]C[-25]:R[484]C[-24],2,1)"
Range("AD3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-28],ReportFormulasRegistradas!R[471]C[-26]:R[502]C[-25],2,1)"
Range("AE3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-29],ReportFormulasRegistradas!R[489]C[-27]:R[520]C[-26],2,1)"
Range("AF3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-30],ReportFormulasRegistradas!R[507]C[-28]:R[538]C[-27],2,1)"
Range("AG3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-31],ReportFormulasRegistradas!R[525]C[-29]:R[556]C[-28],2,1)"
Range("AH3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-32],ReportFormulasRegistradas!R[543]C[-30]:R[574]C[-29],2,1)"
Range("AI3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-33],ReportFormulasRegistradas!R[561]C[-31]:R[592]C[-30],2,1)"
Range("AJ3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-34],ReportFormulasRegistradas!R[579]C[-32]:R[610]C[-31],2,1)"
Range("AK3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-35],ReportFormulasRegistradas!R[597]C[-33]:R[628]C[-32],2,1)"
Range("AL3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-36],ReportFormulasRegistradas!R[615]C[-34]:R[646]C[-33],2,1)"
Range("AM3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-37],ReportFormulasRegistradas!R[633]C[-35]:R[664]C[-34],2,1)"
Range("AN3").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-39],ReportFormulasRegistradas!R[651]C[-36]:R[682]C[-35],2,1)"
Range("AO3").Select
End Sub

 

Adjunto, archivo, una pregunta, si la ubicación de la variable se repite cada 18 filas y el valor siempre está en la misma columna, pregunto su hay una función para optimizar dicho código.

No RepliesBe the first to reply

Resources