Help with Worksheet Change event

mib1019

Board Regular
Joined
Nov 9, 2017
Messages
55
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
  2. MacOS
Thanks in advance for help with this question. Please see the picture below...

After I enter the value in the Project column, Level Calculates from a VLookup, with an error trap that returns 0 if the lookup fails (If(IsErr...

When I leave the Project cell I want the Activity column to autofill with 'Admin', where the VLookup has returned a 0.

Here's my code... which isn't working.

VBA Code:
 Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim ThisRow
    ThisROw = Target.row
        
        If Target.Column = 4 Then
        Dim PLevel
        PLevel = Range("F" & ThisRow).Value
        
        If PLevel = 0 Then
            Range("F" & ThisRow).Value = "Admin"
        End If
        
 End If

1634852456833.png


Thanks!
MB
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

StephenCrump

MrExcel MVP
Joined
Sep 18, 2013
Messages
4,400
Office Version
  1. 365
Platform
  1. Windows
From your description, it sounds like this should be:
PLevel = Range("E" & ThisRow).Value ?

If you make a change inside a Worksheet_Change sub, you'll also need to wrap it like this:

VBA Code:
Application.EnableEvents = False
Range("F" & ThisRow).Value = "Admin"
Application.EnableEvents = True

otherwise you'll trigger another call of the Sub, and possibly an infinite loop.
 
Solution

mib1019

Board Regular
Joined
Nov 9, 2017
Messages
55
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
  2. MacOS
From your description, it sounds like this should be:
PLevel = Range("E" & ThisRow).Value ?

If you make a change inside a Worksheet_Change sub, you'll also need to wrap it like this:

VBA Code:
Application.EnableEvents = False
Range("F" & ThisRow).Value = "Admin"
Application.EnableEvents = True

otherwise you'll trigger another call of the Sub, and possibly an infinite loop.

Well, duhhhh. I feel silly. :-/

Thanks for spotting my silliness, and for the other advise on EnableEvents.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,972
Messages
5,767,400
Members
425,410
Latest member
SmittyT

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
Top