select first sheet to the right in a macro

D

Dan

Hello,
I'm trying to record a macro, in which I need one of the cells to do a
vLookup in the sheet to the right of the active sheet, but I don't know how
to make it insert the name of the sheet to the right.

Here's what I have right now:


ActiveCell.FormulaR1C1 = _
"=IF(RC[-4]="""","""",VLOOKUP(RC[-4],'System 012406'!C[-4]:C,5,FALSE))"


Where it says "System 012406", instead I need it to insert the name of the
next sheet to the right.

Is this possible?


Thank you in advance,

Dan
 
E

Earl Kiosterud

Dan,

Sheets(ActiveSheet.Index + 1)

This refers to the sheet to the right of the active sheet.

Some ways you might use it:
Sheets(ActiveSheet.Index + 1).Select
x = Sheets(ActiveSheet.Index + 1).Range("A1")
 
D

Don Guillett

try

Sub nn()
mysheet = ActiveSheet.Next.Name
ActiveCell.Formula = "=vlookup(1," & mysheet & "!a1:b2,2)"
End Sub
 
Top