Hi All,
Im looking for a way to name and reference sheets to use in formulas within VBA. for example, im using a a vlookup within the code referencing specific sheets. I need to find ways to tell excel to select those sheets in specific regardless of their name or location. The reason for this requirement is to prevent errors month over month when people accidentally name the sheet something different or place it in the wrong place in the workbook..
My Code currently looks like this
instead of the sheet reference "RC1,'Calib_3rd Last'" I would rather just call it latest and have the formulas reference it regardless if its named something else or its location or if it gets deleted or erased.
Any ideas? Im getting desperate.
Thanks guys!
Im looking for a way to name and reference sheets to use in formulas within VBA. for example, im using a a vlookup within the code referencing specific sheets. I need to find ways to tell excel to select those sheets in specific regardless of their name or location. The reason for this requirement is to prevent errors month over month when people accidentally name the sheet something different or place it in the wrong place in the workbook..
My Code currently looks like this
Code:
Sheets("Empower -->").Select
ActiveSheet.Next.Select
Range("BG2").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(VLOOKUP(RC1,Calib_Last!R1C4:R7432C18,7,FALSE),"" "")"
Range("BG2").Select
Selection.AutoFill Destination:=Range("BG2:BG2364")
Range("BG2:BG2364").Select
Range("BG2").Select
Selection.Copy
Range("BH2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = _
"=IFERROR(VLOOKUP(RC1,Calib_Last!R1C4:R7432C18,8,FALSE),"" "")"
Range("BH2").Select
Selection.AutoFill Destination:=Range("BH2:BH2364")
Range("BH2:BH2364").Select
Range("BH2").Select
Selection.Copy
Range("BI2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = _
"=IFERROR(VLOOKUP(RC1,Calib_Last!R1C4:R7432C18,13,FALSE),"" "")"
Range("BI2").Select
Selection.AutoFill Destination:=Range("BI2:BI2364")
Range("BI2:BI2364").Select
Range("BI2").Select
Selection.Copy
Range("BJ2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = _
"=IFERROR(VLOOKUP(RC1,'Calib_2nd Last'!R1C4:R7432C18,13,FALSE),"" "")"
Range("BJ2").Select
Selection.AutoFill Destination:=Range("BJ2:BJ2364")
Range("BJ2:BJ2364").Select
Range("BJ2").Select
Selection.Copy
Range("BK2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = _
"=IFERROR(VLOOKUP(RC1,'Calib_3rd Last'!R1C4:R7432C18,13,FALSE),"" "")"
Range("BK2").Select
Selection.AutoFill Destination:=Range("BK2:BK2364")
Range("BK2:BK2364").Select
Range("BL2").Select
ActiveCell.FormulaR1C1 = "=RIGHT(RC[-3],1)"
Range("BL2").Select
Selection.AutoFill Destination:=Range("BL2:BL2364")
Range("BL2:BL2364").Select
Range("BL2").Select
Selection.Copy
Range("BM2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("BM2:BM2364")
Range("BM2:BM2364").Select
Range("BM2").Select
Selection.Copy
Range("BN2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("BN2:BN2364")
Range("BN2:BN2364").Select
Range("BP2").Select
ActiveCell.FormulaR1C1 = "=LEFT(RC[-7],1)"
Range("BP2").Select
Selection.AutoFill Destination:=Range("BP2:BP2364")
Range("BP2:BP2364").Select
Range("BP2").Select
Selection.Copy
Range("BQ2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("BQ2:BQ2364")
Range("BQ2:BQ2364").Select
Range("BQ2").Select
Selection.Copy
Range("BR2").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll ToRight:=1
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("BR2:BR2364")
Range("BR2:BR2364").Select
Range("A1").Select
Range("A1:BZ7001").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.End(xlUp).Select
Range("BX1").Select
ActiveCell.FormulaR1C1 = "1"
Range("BX1").Select
Selection.Copy
Range("BP2:BR2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlMultiply, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Range("BX1").Select
Selection.ClearContents
End Sub
instead of the sheet reference "RC1,'Calib_3rd Last'" I would rather just call it latest and have the formulas reference it regardless if its named something else or its location or if it gets deleted or erased.
Any ideas? Im getting desperate.
Thanks guys!