VBA stops working when updating formula

MatthewField

New Member
Joined
Jan 5, 2018
Messages
8
Good morning,

I have the following code in my excel sheet, however if i update the range table (In bold below) for the VLOOKUP then the code stops working and I have no clue why it's happening or how to stop it. The range table needs to have the flexibility of having new additions added to it.

The code is as follows:

Private Sub Worksheet_Change(ByVal Target As Range)


Application.EnableEvents = False
If Target.CountLarge > 1 Then Exit Sub
If Target.Column = 2 Then
Target.Offset(, 1).FormulaR1C1 = "=VLOOKUP(rc[-1], Fields!r4c2:r23c3, 2, FALSE)"
ElseIf Target.Column = 7 Then
Target.Offset(, 1).FormulaR1C1 = "=VLOOKUP(rc[-1], Fields!r4c6:r79c7, 2, FALSE)"
End If
Application.EnableEvents = True


End Sub

Could anyone possibly help?

Many thanks,
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi, if your first test is true, i.e. more than one cell has been changed, then you exit the sub and never turn events back on - maybe that is the problem?
 
Last edited:
Upvote 0
Hi, if your first test is true, i.e. more than one cell has been changed, then you exit the sub and never turn events back on - maybe that is the problem?

Thank you for your reply - how would i amend the code to do that? Sorry i'm a complete noob where VBA is concerned.
 
Upvote 0
There's a few ways, the easiest is probably to move the line "Application.EnableEvents = False" after the line "If Target.CountLarge > 1 Then Exit Sub"
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,901
Members
452,948
Latest member
Dupuhini

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