VBA error

paroduso

Board Regular
Joined
Sep 11, 2013
Messages
103
Office Version
  1. 2019
Platform
  1. Windows
Hi everyone...

im trying this simple vba code but im getting an error...

Method 'Formula' of object 'Range' failed

MY EXAMPLE:
cell A1=0,125 B1=1025 C1=1,016 D1=1000 and in cell "E4" will return = A1/B1*C1*D1 but i only want the calculations to be made when in cell "E4" IS NOT BLANK SO , when i type in cell "E2" THE MACRO SHOULD RUN...BUT ONLY WORKS WITH A BOTTON...

Range("E1").Formula = "=RC[-4]/RC[-3]*RC[-2]*RC[-1]"

THANK YOU.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
It needs to be FormulaR1C1.
 
Upvote 0
THIS IS MY MACROS

Sub CAL()

Range("E1").Formula = "=RC[-4]/RC[-3]*RC[-2]*RC[-1]"

End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

If Range("E4").Value <> "" Then

Call CAL

End If

End Sub

IF I ADD THE "CAL" MACRO TO A BOTTON THE MACRO WORKS FINE...BUT WHEN I PUT THIS LINE OF COMMAND ON SHEET1

Private Sub Worksheet_Change(ByVal Target As Range)

If Range("E4").Value <> "" Then

Call CAL

End If

End Sub

ERROR MESSAGE APEARS AND SOMETIMES EXCEL RESTART.
 
Upvote 0
Did you try what I suggested?
 
Upvote 0
HI Fluff...I hadn't seen your answer...I've tried it but it's still the same
 
Upvote 0
I see no reason why you would get a "Method 'Formula' of object 'Range' failed" error on that line, although with the code you have posted you will get a permanent loop.
 
Upvote 0
I see no reason why you would get a "Method 'Formula' of object 'Range' failed" error on that line, although with the code you have posted you will get a permanent loop.
the Excel executes the macro...but the message always appears.
 
Upvote 0
Where are you putting the CAL macro...try it in the same module as the change event
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("E4").Value <> "" Then
Application.EnableEvents = False
Call CAL
Application.EnableEvents = False
End If
End Sub
 
Upvote 0
Solution
Where are you putting the CAL macro...try it in the same module as the change event
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("E4").Value <> "" Then
Application.EnableEvents = False
Call CAL
Application.EnableEvents = False
End If
End Sub
thanks Michael works great...many thanks (y)(y)(y)
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,538
Members
449,038
Latest member
Guest1337

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