I will try and explain this as best I can. I need a way to get a cumbersome formula into a cell using VBA. The formula basically does an xlookup against multiple values and reports a number back into the batch column. For various reasons I may overwrite that value with a manual value, and then set it back to the default formula. The Live Data sheet will contain '000 of users and I have a macro that sets filters the users and manually sets a value. I am trying to write a macro to revert these changes based on the same user filter.
The challenge is that the cells referenced in the start of the formula needs to reference the row for each user and as the list is filtered that isn't as easy as starting at A1 and copying down.
I think I am close, but I just can't get the formula to take in the macro. Below is my current attempt. I have read that you don't need to use $A$1 (for example) when using FormulaR1C1 but I am not sure how to reference the right cell in the second sheet. The & between the elements of the xlookup need updating with CHR(38) I think. But again, I could be way off.
With Range(Range is entered here).SpecialCells(xlCellTypeVisible)
.Formula2R1C1 = "=XLOOKUP(RC[-3]" & CHR(38) & "RC[-2]" & CHR(38) & "RC[-1],'Test Schedule'!$B$1:$B$800 &'Test Schedule'!$C$1:$C$800 & 'Test Schedule'!$D$1:$D$800,'Test Schedule'!$AP$1:$AP$800)"
End With
I could be way off as I am rapidly reaching the ends of my Excel knowledge so no judgement if I am way out in my thinking
Forum Extract.xlsx | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
1 | Id | Primary Name (First Name) | Primary Name (Last Name) | Batch | ||
2 | User ID | FirstName | LastName | 1 | ||
Live Data |
Cell Formulas | ||
---|---|---|
Range | Formula | |
D2 | D2 | =XLOOKUP(A2 & B2 & C2,'Test Schedule'!$B$1:$B$800 &'Test Schedule'!$C$1:$C$800 & 'Test Schedule'!$D$1:$D$800,'Test Schedule'!$AP$1:$AP$800) |
The challenge is that the cells referenced in the start of the formula needs to reference the row for each user and as the list is filtered that isn't as easy as starting at A1 and copying down.
I think I am close, but I just can't get the formula to take in the macro. Below is my current attempt. I have read that you don't need to use $A$1 (for example) when using FormulaR1C1 but I am not sure how to reference the right cell in the second sheet. The & between the elements of the xlookup need updating with CHR(38) I think. But again, I could be way off.
With Range(Range is entered here).SpecialCells(xlCellTypeVisible)
.Formula2R1C1 = "=XLOOKUP(RC[-3]" & CHR(38) & "RC[-2]" & CHR(38) & "RC[-1],'Test Schedule'!$B$1:$B$800 &'Test Schedule'!$C$1:$C$800 & 'Test Schedule'!$D$1:$D$800,'Test Schedule'!$AP$1:$AP$800)"
End With
I could be way off as I am rapidly reaching the ends of my Excel knowledge so no judgement if I am way out in my thinking