Procedure too large on worksheet_change event

samjones833

New Member
Joined
Nov 3, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I have written a worksheet change for each individual cell in a range. When the specific cell is changed it then runs a number of clear contents in a module, for example cell M47 value has changed by selecting a different value in the drop down, this will then clear cells N47:V47. If cell N47 is changed it will then clear cells O47:47 but keep the value in cell M47. The problem i am now getting is that the error message procedure is too large. Below is a snippet of the code, any suggestions on how i could rewrite this would much appreciated.

VBA Code:
Private Sub Worksheet_Change(ByVal target As Range)

Application_Disable




' Main pillars fixed half bolster

    If Not Intersect(target, Range("M47")) Is Nothing Then

        Worksheet_SelectionChangeCentreDrillDirectionPillarsFixedBol

    End If

    If Not Intersect(target, Range("N47")) Is Nothing Then

        Worksheet_SelectionChangeCentreDrillTolerancePillarsFixedBol

    End If

    If Not Intersect(target, Range("O47")) Is Nothing Then

        Worksheet_SelectionChangeCentreDrillTypePillarsFixedBol

    End If

    If Not Intersect(target, Range("R47")) Is Nothing Then

        Worksheet_SelectionChangeCentreDrillMaterialPillarsFixedBol

    End If

    If Not Intersect(target, Range("S47")) Is Nothing Then

        Worksheet_SelectionChangeCentreDrillCoatingPillarsFixedBol

    End If

     If Not Intersect(target, Range("V47")) Is Nothing Then

        Worksheet_SelectionChangeDrillDirectionMainPillarBolster

    End If

Application_Enable

End sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Welcome to the forum.

I can't see, based on what you describe, why you need a separate macro for each cell, since they all sound like they do much the same thing.

Given the nature of the error message, there must be a lot more code involved - how many cells are you monitoring?
 
Upvote 0
Welcome to the forum.

I can't see, based on what you describe, why you need a separate macro for each cell, since they all sound like they do much the same thing.

Given the nature of the error message, there must be a lot more code involved - how many cells are you monitoring?
Hi,

Yes the module that is activated by the cell value change will simply clear the contents of the cells in front of it. For example M47's value is changed from a drop down, the cells infront of it will then clear to give users a blank row to input new details.

There are 1,020 cells that are required for this, currently each with a seprerate line of code.
 
Upvote 0
Is there anything in the columns after col V that needs to be kept?
 
Upvote 0
Ok, how about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("M47:V100")) Is Nothing Then
      Application.EnableEvents = False
      Range(Target.Offset(, 1), Range("V" & Target.Row)).ClearContents
      Application.EnableEvents = True
   End If
End Sub
Change the V100 to what ever the last row should be
 
Upvote 0
Solution
Ok, how about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("M47:V100")) Is Nothing Then
      Application.EnableEvents = False
      Range(Target.Offset(, 1), Range("V" & Target.Row)).ClearContents
      Application.EnableEvents = True
   End If
End Sub
Change the V100 to what ever the last row should be
That works perfectly! Thankyou
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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