vba help on lr

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

I have 5 sheets, and in column B of every worksheet I want to apply vlookup formula, after applying a formula, I want to autofill that formula till last row.

Shall I need to create different LR?... Cells.(rows.count,1).end(xlup).row

for different sheets. Please suggest.

Thanks in advance !!!
Regards,
Mallesh Gangadhar
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi,

A couple of questions...

What is going to trigger the macro?
Is the formula always going to be the same?
Is it the same formula for every sheet?
Are there any other sheets in the workbook other than the "5 sheets"?
Is the formula going to start in the same row in Column B on every sheet?
 
Last edited:
Upvote 0
With no specifics to go on, here's an example assuming:
It's doing every sheet in the book
Formula should start in B2 on each sheet
Formula is referring to A2 on each sheet
Lookup range is E2:F100
Formula goes down as far as data exists in column A.

Code:
Sub Test()
Dim ws As Worksheet, lr As Long
For Each ws In Worksheets
    lr = ws.Cells(Rows.Count, "A").End(xlUp).Row
    ws.Range("B2:B" & lr).Formula = "=VLOOKUP(A2,$E$2:$F$100,2,FALSE)"
Next ws
End Sub
 
Last edited:
Upvote 0
Hello sir,

Thanks for your help , looking for One more help plz.

I want this formula only in sheet1,sheet2, and sheet4. I don't want to run looping in sheet3 and sheet 5.
My formula start at B2 in each sheets. look up value and look up data is same for all sheets. I have given Name to my range as (data)

also Can you suggest if my data is in different workbook , how to select that files data and use in current workbook.

I am new to vba, just started leaning the concept. Please assist. Thank you so much .


Regards,
Mallesh
 
Upvote 0
This will restrict it to a list of specified sheet names.
And will use data as the named range for the lookup range

Code:
Sub Test()
Dim ws As Worksheet, lr As Long
For Each ws In Worksheets
    Select Case ws.Name
        Case "Sheet1", "Sheet2", "Sheet5"
            lr = ws.Cells(Rows.Count, "A").End(xlUp).Row
            ws.Range("B2:B" & lr).Formula = "=VLOOKUP(A2,data,2,FALSE)"
    End Select
Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,764
Messages
6,126,750
Members
449,335
Latest member
Tanne

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