To minimise the amount of changes I need to make when this bit of code is duplicated for other filenames, ALPHA-L4L.xlsm changing to BRAVO-L4L.xlsm and so on, I assigned the .xlsm file and its path to a variable so that I only need to make the change once (see black and bolded). Which is utilised successfully in Range("W1").Value = "L4L" & vbLf & Format(FileDateTime(FilePath), "dd mmm")
But I also need to utilise this variable within the code which will be inserted as a formula in to a cell (see red and bolded) but I am unable to get it to work.
I have tried concatenating the [ ] into the appropriate locations but can not get it to accept it and work.
What is the correct method/procedure/syntax to achieve this??
Thanking the many in advance for their assistance.
Dim FilePath As String
FilePath = "Z:\Price Updates\Scrap\ALPHA-L4L.xlsm"
Range("W:X").EntireColumn.Hidden = False
If Columns("W").Hidden = False Then
Range("W1").Value = "L4L" & vbLf & Format(FileDateTime(FilePath), "dd mmm")
Range("W3").Formula = "=IFERROR(NUMBERVALUE(VLOOKUP(A2,'Z:\Price Updates\Scrap\[ALPHA-L4L.xlsm]SCRAP Latest'!$A:$F,4,FALSE)),""-"")"
Range("X3").Formula = "=IF(OR(ISERROR(NUMBERVALUE(VLOOKUP(A2,'Z:\Price Updates\Scrap\[ALPHA-L4L.xlsm]SCRAP Previous'!$A:$F,4,FALSE))),ISERROR(NUMBERVALUE(VLOOKUP(A2,'Z:\Price Updates\Scrap\[ALPHA-L4L.xlsm]SCRAP Previous'!$A:$F,4,FALSE)))),""""," _
& Chr(10) & "IF(VLOOKUP(A2,'Z:\Price Updates\Scrap\[ALPHA-L4L.xlsm]SCRAP Latest'!$A:$F,4,FALSE)<VLOOKUP(A2,'Z:\Price Updates\Scrap\[ALPHA-L4L.xlsm]SCRAP Previous'!$A:$F,4,FALSE),""ò""," _
& Chr(10) & "IF(VLOOKUP(A2,'Z:\Price Updates\Scrap\[ALPHA-L4L.xlsm]SCRAP Latest'!$A:$F,4,FALSE)>VLOOKUP(A2,'Z:\Price Updates\Scrap\[ALPHA-L4L.xlsm]SCRAP Previous'!$A:$F,4,FALSE),""ñ"",""ó"")))"
Else
Range("W1").Value = "L4L" & vbLf & "IGNORE"
Range("W2").Value = "-"
Range("X2").Value = ""
End If
But I also need to utilise this variable within the code which will be inserted as a formula in to a cell (see red and bolded) but I am unable to get it to work.
I have tried concatenating the [ ] into the appropriate locations but can not get it to accept it and work.
What is the correct method/procedure/syntax to achieve this??
Thanking the many in advance for their assistance.
Dim FilePath As String
FilePath = "Z:\Price Updates\Scrap\ALPHA-L4L.xlsm"
Range("W:X").EntireColumn.Hidden = False
If Columns("W").Hidden = False Then
Range("W1").Value = "L4L" & vbLf & Format(FileDateTime(FilePath), "dd mmm")
Range("W3").Formula = "=IFERROR(NUMBERVALUE(VLOOKUP(A2,'Z:\Price Updates\Scrap\[ALPHA-L4L.xlsm]SCRAP Latest'!$A:$F,4,FALSE)),""-"")"
Range("X3").Formula = "=IF(OR(ISERROR(NUMBERVALUE(VLOOKUP(A2,'Z:\Price Updates\Scrap\[ALPHA-L4L.xlsm]SCRAP Previous'!$A:$F,4,FALSE))),ISERROR(NUMBERVALUE(VLOOKUP(A2,'Z:\Price Updates\Scrap\[ALPHA-L4L.xlsm]SCRAP Previous'!$A:$F,4,FALSE)))),""""," _
& Chr(10) & "IF(VLOOKUP(A2,'Z:\Price Updates\Scrap\[ALPHA-L4L.xlsm]SCRAP Latest'!$A:$F,4,FALSE)<VLOOKUP(A2,'Z:\Price Updates\Scrap\[ALPHA-L4L.xlsm]SCRAP Previous'!$A:$F,4,FALSE),""ò""," _
& Chr(10) & "IF(VLOOKUP(A2,'Z:\Price Updates\Scrap\[ALPHA-L4L.xlsm]SCRAP Latest'!$A:$F,4,FALSE)>VLOOKUP(A2,'Z:\Price Updates\Scrap\[ALPHA-L4L.xlsm]SCRAP Previous'!$A:$F,4,FALSE),""ñ"",""ó"")))"
Else
Range("W1").Value = "L4L" & vbLf & "IGNORE"
Range("W2").Value = "-"
Range("X2").Value = ""
End If
Last edited: