VLOOKUP VBA looping multiple worksheets

financehelp_excel

New Member
Joined
May 18, 2015
Messages
5
Thanks in advance for solving this.

I've created a macro but it's returning an error. I have a two column list in my first sheet and I want VLOOKUP to go down the list. So for cell C1 sheet 2, I want it to lookup Cell A2 in sheet named "First". For cell C1 in sheet 3, I want it to lookup Cell A3 in sheet named "First".

Here's what I have so far:

'Sub test()
Dim First As Integer, Last As Integer, i As Integer
First = Sheets("First").Index
Last = Sheets("Last").Index
For i = First + 1 To Last - 1
With Sheets(i)
'Range("C1").Select
'Range("C1") = Application.WorksheetFunction.VLookup(Sheets("First").Range("A1+1"), Sheets("First").Range("$A$1:$B504"), 2, False)
End With
Next i
End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Please test this:

Code:
Sub test()
Dim i%, f As Worksheet
Set f = Sheets("First")
For i = Sheets("First").Index + 1 To Sheets("Last").Index - 1
    Sheets(i).Range("C1") = Application.WorksheetFunction.VLookup _
    (f.Range("A" & i), f.Range("$A$1:$B504"), 2, False)
Next
End Sub
 
Upvote 0
Like this:

Code:
Sub Renaming()
Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
    If Len(sh.Range("c1")) > 0 Then sh.Name = sh.Range("c1")
Next
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,772
Messages
6,126,807
Members
449,339
Latest member
Cap N

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