Excel smart calculation

alliswell

Board Regular
Joined
Mar 16, 2020
Messages
190
Office Version
  1. 2007
Platform
  1. Windows
  2. Mobile
I want is, if A1 and b1 has value then C1 must get value by multiplying A1 and b1 and after clearing A1:C1, if A1 and C1 has value then then b1 must get value by dividing A1 by C1 and after clearing A1: C1, if B1 and C1 has value then A1 must get value By dividing B1 by C1.

If formula can do it it's better or else macro. Thanks every body.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
If formula can do it it's better or else macro.
You cannot do that with formulas.

You can try this Worksheet_Change event code. To implement ..
1. Right click the sheet name tab and choose "View Code".
2. Copy and Paste the code below into the main right hand pane that opens at step 1.
3. Test

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim rng As Range, rNums As Range
  Dim c As Long

  Set rng = Range("A1:C1")
  If Not Intersect(Target, rng) Is Nothing Then
    On Error Resume Next
    Set rNums = rng.SpecialCells(xlConstants, xlNumbers)
    On Error GoTo 0
    If Not rNums Is Nothing Then
      If rNums.Count = 2 Then
        Application.EnableEvents = False
        c = IIf(rNums.Areas.Count = 1, (2 * rNums.Column + 1) Mod 4, 2)
        If c = 3 Then
          rng.Cells(c).Value = rng.Cells(1).Value * rng.Cells(2).Value
        Else
          rng.Cells(c).Value = rng.Cells(3).Value / rng.Cells(3 - c).Value
        End If
        Application.EnableEvents = True
      End If
    End If
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,473
Messages
6,125,012
Members
449,204
Latest member
tungnmqn90

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