referencing a cell value that is populated from a vlookup

Blanchetdb

Board Regular
Joined
Jul 31, 2018
Messages
164
Office Version
  1. 365
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

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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