schroederdj
New Member
- Joined
- Jun 21, 2022
- Messages
- 14
- Office Version
- 365
- Platform
- Windows
I want to use the below XLOOKUP formula in VBA but as I loop through additional rows I want the R[-1]C[2] (in red below) to stay fixed. (like when you use $K$1 in a regular excel formula. Is that possible? Another solution I thought of was to use a counter to take the R[-1]C[2] and subtract another R1 each loop which would essentially keep it at the original fixed position. Thanks for your help
Sub ListSheet()
Dim ws As String
'get previous day tab name
ws = ActiveSheet.Next.Name
Range("k1:k1").Select
ActiveCell = ws
'XLOOKUP Formula to previous tab report
Range("I2").Select
Do While ActiveCell.Offset(0, -1) <> ""
ActiveCell.Formula2R1C1 = _
"=XLOOKUP(RC[-5],(INDIRECT(""'""&R[-1]C[2]&""'!D:D"")),(INDIRECT(""'""&R[-1]C[2]&""'!I:I"")))"
ActiveCell.Offset(1, 0).Select
Loop
End Sub
Sub ListSheet()
Dim ws As String
'get previous day tab name
ws = ActiveSheet.Next.Name
Range("k1:k1").Select
ActiveCell = ws
'XLOOKUP Formula to previous tab report
Range("I2").Select
Do While ActiveCell.Offset(0, -1) <> ""
ActiveCell.Formula2R1C1 = _
"=XLOOKUP(RC[-5],(INDIRECT(""'""&R[-1]C[2]&""'!D:D"")),(INDIRECT(""'""&R[-1]C[2]&""'!I:I"")))"
ActiveCell.Offset(1, 0).Select
Loop
End Sub