referencing a cell value that is populated from a vlookup

Blanchetdb

Board Regular
Joined
Jul 31, 2018
Messages
161
Office Version
  1. 2016
Platform
  1. Windows
Hi

I require to reference a cell value using an IF statement. The issue is that the cell value is populated from a vlookup and when I try the IF statement, the desired result does not happen

this is the VLookup : =IFERROR(VLOOKUP(IND_LOO_Builder_ENG!L9,Position_List_ENG!2:10004,18,FALSE),"") which is located in cell AI6 and populates a value



the IF statement in VBA is
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range) ' Form Manipulation / Hide and Unhide rows
 

'Hours of Work
If Range("AI6") = "PE" Then
Worksheets("IND_LOO_Builder_ENG").Range("36:42").EntireRow.Hidden = True
 Else
Worksheets("IND_LOO_Builder_ENG").Range("36:42").EntireRow.Hidden = False
End If

End sub

The process does not seem to recognize the value "PE" in cell AI6 but if I type the value PE in the cell without using the vlookup to populate, the process works
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
The change event is not triggered by formulae, as the cell has not changed.
You could use the calculate event, but that will trigger whenever any cell on the sheet is recalculated.
 
Upvote 0
The change event is not triggered by formulae, as the cell has not changed.
You could use the calculate event, but that will trigger whenever any cell on the sheet is recalculated.

thank you for responding....

unfortunately I have absolutely no idea what you mean as I am a rookie when it comes to VBA. I am able to reference a cell value when the value is typed into the cell (If I type PE in a cell and reference that cell....then the process works) but when the cell is populated from a formula.... nothing happens

am I missing something in my IF statement or should a refer to the cell other than Range("AI6")?
 
Upvote 0
The code you are using is a change event & that does not work with formulae.
You can use
VBA Code:
Private Sub Worksheet_Calculate()
'Hours of Work
If Range("AI6") = "PE" Then
Worksheets("IND_LOO_Builder_ENG").Range("36:42").EntireRow.Hidden = True
 Else
Worksheets("IND_LOO_Builder_ENG").Range("36:42").EntireRow.Hidden = False
End If
End Sub
But it could bring you sheet to a grinding halt, as it will run whenever any formula on that sheet calculates.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,624
Latest member
gregg777

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top