Jumparound
New Member
- Joined
- Aug 4, 2015
- Messages
- 45
- Office Version
- 2016
- Platform
- Windows
Hi,
I have a sheet where cells L12 to L89 have formulas in that looks at values entered in I12 to I89, if there is only one match it returns that, if there are multiple matches it returns nothing.
e.g.
I then have a data validation on the cells in L12 to L89 which looks up the possible matches and lists them in a drop down which the user can select from.
The issue is that when the user selects one of these values from the drop down it overwrites the cell contents and so the formula in the cell is lost so if the user changes the value in column I it will no longer auto populate if there is only one result.
I tried to fix this with some VBA which would paste the formulas back in when one of the cells from I12 to I89 was changed. However, this replaces all of the values in cells L12 to L89 so would overwrite anything the user had already done
I think the solution to this is to change the vba to only update the cell in column L that is in the same row as the cell that has been changed in column I. If anyone could help it would be greatly appreciated!
I have a sheet where cells L12 to L89 have formulas in that looks at values entered in I12 to I89, if there is only one match it returns that, if there are multiple matches it returns nothing.
e.g.
Excel Formula:
=IF(I12="","",IF(VLOOKUP(Q12,Sheet1!$A$39:$C$2375,3,0)="",VLOOKUP(Q12,Sheet1!$A$39:$C$2375,2,0),""))
I then have a data validation on the cells in L12 to L89 which looks up the possible matches and lists them in a drop down which the user can select from.
The issue is that when the user selects one of these values from the drop down it overwrites the cell contents and so the formula in the cell is lost so if the user changes the value in column I it will no longer auto populate if there is only one result.
I tried to fix this with some VBA which would paste the formulas back in when one of the cells from I12 to I89 was changed. However, this replaces all of the values in cells L12 to L89 so would overwrite anything the user had already done
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
' The variable KeyCells contains the cells that will
' insert the formulas when they are changed.
Set KeyCells = Range("I12:I89")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
' Insert the formulas when one of the designated cells has been
' changed.
Range("L12:L89").Formula = "=IF(I12="""","""",IF(VLOOKUP(Q12,Sheet1!$A$39:$C$2375,3,0)="""",VLOOKUP(Q12,Sheet1!$A$39:$C$2375,2,0),""""))"
End If
End Sub
I think the solution to this is to change the vba to only update the cell in column L that is in the same row as the cell that has been changed in column I. If anyone could help it would be greatly appreciated!