Help with Worksheet Change event

mib1019

Board Regular
Joined
Nov 9, 2017
Messages
65
Office Version
  1. 365
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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
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.
 
Upvote 0
Solution
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.
 
Upvote 0

Forum statistics

Threads
1,213,530
Messages
6,114,162
Members
448,554
Latest member
Gleisner2

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