Dear experts,
I hope you can assist me.
I am using a variable called "MyCell", it contains the address of the cell 3 columns left of the activecell.
This address is later on being used in the vlookup formula's however the outcome produces an error.
When I use the Activecell.formula statement the formula on the spreadsheet looks like this:
=IF(VLOOKUP(I10,'[Approved.xls]Page 1'!C1:C31,31,FALSE)="pending","Pending "&VLOOKUP(I10,'[Pending Approval.xls]Page 1'!C1:C29,29,FALSE),VLOOKUP(I10,'[Approved.xls]Page 1'!C1:C31,31,FALSE))
This produces an #N/A error
When I change the below code ActiveCell.Formula to ActiveCell.FormulaR1C1 the formula looks like this:
=IF(VLOOKUP('I10','[Approved.xls]Page 1'!$A:$AE,31,FALSE)="pending","Pending "&VLOOKUP('I10','[Pending Approval.xls]Page 1'!$A:$AC,29,FALSE),VLOOKUP('I10','[Approved.xls]Page 1'!$A:$AE,31,FALSE))
This produces the #NAME error as there are single quotes around the cell address e.g 'I10'
Are you able to provide an solution?
Many thanks.
I hope you can assist me.
I am using a variable called "MyCell", it contains the address of the cell 3 columns left of the activecell.
This address is later on being used in the vlookup formula's however the outcome produces an error.
When I use the Activecell.formula statement the formula on the spreadsheet looks like this:
=IF(VLOOKUP(I10,'[Approved.xls]Page 1'!C1:C31,31,FALSE)="pending","Pending "&VLOOKUP(I10,'[Pending Approval.xls]Page 1'!C1:C29,29,FALSE),VLOOKUP(I10,'[Approved.xls]Page 1'!C1:C31,31,FALSE))
This produces an #N/A error
When I change the below code ActiveCell.Formula to ActiveCell.FormulaR1C1 the formula looks like this:
=IF(VLOOKUP('I10','[Approved.xls]Page 1'!$A:$AE,31,FALSE)="pending","Pending "&VLOOKUP('I10','[Pending Approval.xls]Page 1'!$A:$AC,29,FALSE),VLOOKUP('I10','[Approved.xls]Page 1'!$A:$AE,31,FALSE))
This produces the #NAME error as there are single quotes around the cell address e.g 'I10'
Are you able to provide an solution?
Many thanks.
Code:
Sub DailyOps()
Dim MyCell As String
MyCell = Replace((ActiveCell.Offset(0, -3).Address), "$", "")
ActiveCell.Formula = _
"=IF(VLOOKUP(" & MyCell & ",'[Approved.xls]Page 1'!C1:C31,31,FALSE)=""pending"",""Pending ""&VLOOKUP(" & MyCell & ",'[Pending Approval.xls]Page 1'!C1:C29,29,FALSE),VLOOKUP(" & MyCell & ",'[Approved.xls]Page 1'!C1:C31,31,FALSE))"
End Sub
Last edited: