Farhan Mahmood
asked on
VBA Excel Vlooup Macro Help for Dynamic Range
Respected All,
Hope you are all Fine i have recorded a macro with vlookup formula it comes in R1C1 format Please advice how to make Criteria Range Which is (Sheet1!R[-57]C[-5]:R[186] C[17] = B1:S244) Dynamic so that if some data Added in last row which will be 245 it Will auto include in range.
Sub VlookupExtractRecoveries()
'Code to Apply Vloockup Formula to Extract Figures in Recovery Report
Dim LR As Long
LR = Range("G58").End(xlDown).R ow
Range("G58").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(VLOOKUP(RC[-5],S heet1!R[-5 7]C[-5]:R[ 186]C[17], COLUMNS(Sh eet1!R[152 ]C[-5]:R[1 52]C[10]), 0),0)"
Range("G58").Select
Selection.AutoFill Destination:=Range("G58:G" & LR), Type:=xlFillDefault
Range("G58").Select
'Code to Convert Formula as Peste Special value
Range(Selection, Selection.End(xlDown).Offs et(-1)).Se lect
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Code for Esc Copy Cut or Cancel Sellectoion
Application.CutCopyMode = False
End Sub
Hope you are all Fine i have recorded a macro with vlookup formula it comes in R1C1 format Please advice how to make Criteria Range Which is (Sheet1!R[-57]C[-5]:R[186]
Sub VlookupExtractRecoveries()
'Code to Apply Vloockup Formula to Extract Figures in Recovery Report
Dim LR As Long
LR = Range("G58").End(xlDown).R
Range("G58").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(VLOOKUP(RC[-5],S
Range("G58").Select
Selection.AutoFill Destination:=Range("G58:G"
Range("G58").Select
'Code to Convert Formula as Peste Special value
Range(Selection, Selection.End(xlDown).Offs
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Code for Esc Copy Cut or Cancel Sellectoion
Application.CutCopyMode = False
End Sub
Try below:
Sub VlookupExtractRecoveries()
Dim Ws As Worksheet
'Code to Apply Vloockup Formula to Extract Figures in Recovery Report
Dim LR As Long
LR = Ws.Range("B" & Rows.Count).End(xlDown).Row
Ws.Range("G58:G" & LR).FormulaR1C1 = "=IFERROR(VLOOKUP(RC2,Sheet1!R1C2:R244C24,COLUMNS(Sheet1!R210C2:R210C17),0),0)"
'Code to Convert Formula as Peste Special value
Ws.Range("G58:G" & LR).Value = Ws.Range("G58:G" & LR).Value
End Sub
ASKER
Respected Sir,
I Want This Range Sheet1!R1C2:R244C24 dynamic instead G58 to G
Please Kindly Review My Question.
Thanks Aloot For Earlier Response.
Waiting???
Regards
I Want This Range Sheet1!R1C2:R244C24 dynamic instead G58 to G
Please Kindly Review My Question.
Thanks Aloot For Earlier Response.
Waiting???
Regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dear Sir Shums,
Your Code Helped me with a Little bit addition of Offset. Thanks
Sub VlookupExtractRecoveries9( )
Dim Ws As Worksheet
'Code to Apply Vloockup Formula to Extract Figures in Recovery Report
Dim LR As Long
Set Ws = ActiveSheet
LR = Ws.Range("G57").End(xlDown ).Row
Ws.Range("G57:G" & LR).Offset(-1).FormulaR1C1 = "=IFERROR(VLOOKUP(RC2,Shee t1!C2:C24, COLUMNS(Sh eet1!R210C 2:R210C17) ,0),0)"
'Code to Convert Formula as Peste Special value
Ws.Range("G57:G" & LR).Offset(-1).Value = Ws.Range("G57:G" & LR).Offset(-1).Value
End Sub
Your Code Helped me with a Little bit addition of Offset. Thanks
Sub VlookupExtractRecoveries9(
Dim Ws As Worksheet
'Code to Apply Vloockup Formula to Extract Figures in Recovery Report
Dim LR As Long
Set Ws = ActiveSheet
LR = Ws.Range("G57").End(xlDown
Ws.Range("G57:G" & LR).Offset(-1).FormulaR1C1
'Code to Convert Formula as Peste Special value
Ws.Range("G57:G" & LR).Offset(-1).Value = Ws.Range("G57:G" & LR).Offset(-1).Value
End Sub
ASKER