Vlookup Macro

lakshmipathi123

Board Regular
Joined
Jul 10, 2012
Messages
52
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have query regarding vlookup macro. I have recorded a macro for vlookup and its working for selected data (100 columns only) but if i add/delete few rows/columns macro not working for add/delete rows/columns.

I need a vba code which should select based data availability. Not only vlookup, anyother formula if i use it should select 1st row to last row (only data available cells).

Appreciate your help on this :)

Thank you in advance
Lakshmipathi+
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Can we see your code?

Dom

Hi Domski,

Thanks for your prompt reply :). Please find below 2 formula codes i used in both i need macro to calculate data range irrespective recorded range K40227. Macro should find last row where the data availability.

EOMONTH CODE

Range("K2").Select
ActiveCell.FormulaR1C1 = "=EOMONTH(RC[-1],RC[2]-1)"
Range("K2").Select
Selection.Copy
Range("J2").Select
Selection.End(xlDown).Select
Range("K40228").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("K40227").Select
Selection.End(xlUp).Select

VLOOKUP CODE

Columns("Y:Y").Select
Selection.Insert Shift:=xlToRight
Range("Y1").Select
ActiveCell.FormulaR1C1 = "BU"
Range("Y2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],BU!C[-22]:C[-16],7,0)"
Range("Y2").Select
Selection.Copy
Range("X2").Select
Selection.End(xlDown).Select
Range("Y40228").Select
Range(Selection, Selection.End(xlUp)).Select
Selection.SpecialCells(xlCellTypeVisible).Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=-12
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("Y40227").Select
Selection.End(xlUp).Select
 
Upvote 0
Hi,

Like this I think:

EOMONTH:

Code:
With Range("K2:K" & Range("J" & Rows.Count).End(xlUp).Row)
    .FormulaR1C1 = "=EOMONTH(RC[-1],RC[2]-1)"
    .Value = .Value
End With

VLOOKUP:

Code:
Columns("Y:Y").Insert Shift:=xlToRight
Range("Y1") = "BU"
With Range("Y2:Y" & Range("X" & Rows.Count).End(xlUp).Row)
    .FormulaR1C1 = "=VLOOKUP(RC[-1],BU!C[-22]:C[-16],7,0)"
    .Value = .Value
End With

Dom
 
Upvote 0
Hi,

Like this I think:

EOMONTH:

Code:
With Range("K2:K" & Range("J" & Rows.Count).End(xlUp).Row)
    .FormulaR1C1 = "=EOMONTH(RC[-1],RC[2]-1)"
    .Value = .Value
End With

VLOOKUP:

Code:
Columns("Y:Y").Insert Shift:=xlToRight
Range("Y1") = "BU"
With Range("Y2:Y" & Range("X" & Rows.Count).End(xlUp).Row)
    .FormulaR1C1 = "=VLOOKUP(RC[-1],BU!C[-22]:C[-16],7,0)"
    .Value = .Value
End With

Dom

Hi Dom,

It's working...Thanks a lot for your help :). I have few more issues that i'll let u know later

Thank you again
Lakshmipathi
 
Upvote 0
Hi Dom,

It's working...Thanks a lot for your help :). I have few more issues that i'll let u know later

Thank you again
Lakshmipathi

Hi,

My Look-up value range contains many blank cells I'd like to remain blank. This code works to populate that range as needed, but the blank cells all show a #NA result. How can I edit this (or another?) macro to leave the blank cells empty?
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,126
Members
452,381
Latest member
Nova88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top