EXCEL VBA procedure ambigous name

My VBA code is too large and I'm trying to make smaller SUBS so the error won't come up, but then the error "Ambigoius name" pops up. I've tried to rename my subs... Ex.

Private Sub worksheet_calculate()
Range("I9").Interior.Color=Range("AK9").Display.Format.Interior.Color
end sub
Private Sub worksheet_calculate2()
Range("J9").Interior.Color=Range("AQ9").Display.Format.Interior.Color
end sub

...when I rename the other subs as shown in the example it doesn't do anything, only the original work properly. How do I rename them so they can work properly?

Upvotes: 0

Views: 69

Answers (2)

Poutnik
Poutnik

Reputation: 191

In my understanding, worksheet_calculate is the predefined name of the subroutine, triggered by the event when the worksheet is recalculated.

You can define and call other private subs from it. like

Private Sub worksheet_calculate()
   rem sub body
   CalculateSub1 pars        'variant one
   Call CalculateSub1(pars)  'variant two
   rem sub body
End Sub

Sub CalculateSub1(pars)
   Rem Sub body
End Sub 

Upvotes: 1

Harsh Dubey
Harsh Dubey

Reputation: 131

Just insert the below line of codes at the end of your main sub which is "worksheet_calculate"

Call worksheet_calculate2
Call worksheet_calculate3
Call worksheet_calculate4
Call worksheet_calculate4
.
.
.
Call worksheet_calculaten

Upvotes: 0

Related Questions