Using the loop function of VBA, I'm wanting to input the same formula into the same cell on each worksheet in my workbook.
I've tried the following code, but it doesn't loop through all worksheets. It only updates the one that happens to be selected by default:
Sub insertformula() Dim ws As Worksheet For Each ws In ActiveWorkbook.Worksheets Range("D7").Select ActiveCell.FormulaR1C1 = "=VLOOKUP(R[-5]C[-1],'SHEET ALL WILL REFERENCE'!C[-2]:C[-1],2,FALSE)" Next End Sub
What am I missing that's keeping this code from looping through all the worksheets?