circular formula

Wolfmanfafa

New Member
Joined
Nov 22, 2017
Messages
5
All of my google-fu has failed me. Everything I find says a formula in excel cannot be calculated if anything in the formula refers to itself. I know there is a way to do this. I have seen it done before.

What I want to do is create a simple formula to calculate Watts = Volts x Amps
I have created a table in which each line contains all 3 columns (watts volts amps) respectively
The voltage will have to be entered by the user, as well as one of the remaining variables.

I want it so when the voltage and another variable (either amps or watts) is entered, excel returns the value of the remaining variable.

Any ideas?

Thanks
 

Some videos you may like

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Scott T

Well-known Member
Joined
Dec 14, 2016
Messages
2,615
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
You could use a change event to do this.

The code is written with watts in Column A Volts in B and Amps in C and assuming row 1 are headers

right click on the tab with your table and select view code past the code below
when you enter something in column A-C in row 2 or below the code will run


Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim currow As Long
currow = Target.Row
If currow <> 1 Or Not IsText(Target) Then
    Application.EnableEvents = False
    
    
    If Target.Column = 1 And Range("B" & currow) <> 0 Then Range("C" & currow) = Range("A" & currow) / Range("B" & currow)
    If Target.Column = 2 And Range("A" & currow) <> "" Then Range("C" & currow) = Range("A" & currow) / Range("B" & currow)
    
    If Target.Column = 3 And Range("B" & currow) <> 0 Then Range("A" & currow) = Range("B" & currow) * Range("C" & currow)
    If Target.Column = 2 And Range("C" & currow) <> "" Then Range("A" & currow) = Range("B" & currow) * Range("C" & currow)
    
    Application.EnableEvents = True
End If
End Sub

The file will need to be saved as a macro enabled file type such as XLSM
 
Last edited:

BrianJN1

Well-known Member
Joined
Jun 15, 2017
Messages
603
Withdrawn - The reply above may actually contradict what I was posting.
 
Last edited:

Wolfmanfafa

New Member
Joined
Nov 22, 2017
Messages
5
I thought I was fairly proficient with excel. Not anymore!

I haven't really dealt with macros before, other than basic stuff covered in intro excel (ITM 105 was the title of the college course)

I copied and pasted the code. Then, I changed A,B,C to B,C,D because column A is the name of the appliance. Then, I entered a value in A7 (row 1 is my title. row 2 is my table headers. rows 3-6 had manual entries already entered)

I got a "Compile Error: sub or function not defined"
IsText was highlighted like this:
If currow <> 1 Or Not IsText(Target) Then

Is this because row 1 is not my table headers row?
 

Scott T

Well-known Member
Joined
Dec 14, 2016
Messages
2,615
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Try changing it to
Code:
If currow <> 1 Or Not Application.IsText(Target) Then
 

Watch MrExcel Video

Forum statistics

Threads
1,122,656
Messages
5,597,390
Members
414,141
Latest member
Joey_T92

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
Top