Math operation between a column with unique formulas and another column

dejhantulip

Board Regular
Joined
Sep 9, 2015
Messages
58
Office Version
  1. 365
Platform
  1. Windows
Hello guys!

So I've been having this situation quite often, and I have searched and thought of something to solve my problem but haven't been able to find anything.

I have a two columns. Column F and G.
In Column F I have several rows of information, each row is unique, some are values and some are formulas.
Because of the nature of the work I do, sometimes I need to "affect" each of the cells in Column F with a factor (multiplying, or dividing, or sometimes even adding or substracting) in Column G.

For example, as you can see in the attached image:
1) Cell F10 has a hard-entered number 0.60, in this case I would like the cell to be =(0.60)*G10
2) Cell F11 has the formula =E11*$J$13 and in this case I would like the cell to be =(E11*$J$13)*G11

That is the basic idea. I guess I would have to use some kind of VBA code... but I am not sure.
Anyone could help me out?

Thank you very much in advance! :)
 

Attachments

  • Problems.png
    Problems.png
    15.6 KB · Views: 15

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try...

VBA Code:
Sub AppendFormulaFromSingleCell()
    Dim myCell As Range, myRng As Range, lr As Long
 
    Dim xSRg As Range                            'ONB
  
 
    Set myRng = Selection
    On Error Resume Next
    Set xSRg = Application.InputBox("Select CELL to be multiplied to previously selected range:", "Test", "xTxt", , , , , 8) 'ONB
    On Error GoTo 0
    
    If xSRg Is Nothing Then Exit Sub             'ONB

    For Each myCell In myRng
        If myCell.Value <> "" Then
            If Not myCell.HasFormula Then
                myCell.Formula = "=" & myCell.Value & "*" & xSRg.Address 'Range("$B$2").Address
            Else
                myCell.Formula = "=(" & Replace(myCell.Formula, "=", "") & ")" & "*" & xSRg.Address 'Range("$B$2").Address
            End If
        End If
    Next

End Sub
 
Upvote 0
Try...

VBA Code:
Sub AppendFormulaFromSingleCell()
    Dim myCell As Range, myRng As Range, lr As Long

    Dim xSRg As Range                            'ONB
 

    Set myRng = Selection
    On Error Resume Next
    Set xSRg = Application.InputBox("Select CELL to be multiplied to previously selected range:", "Test", "xTxt", , , , , 8) 'ONB
    On Error GoTo 0
   
    If xSRg Is Nothing Then Exit Sub             'ONB

    For Each myCell In myRng
        If myCell.Value <> "" Then
            If Not myCell.HasFormula Then
                myCell.Formula = "=" & myCell.Value & "*" & xSRg.Address 'Range("$B$2").Address
            Else
                myCell.Formula = "=(" & Replace(myCell.Formula, "=", "") & ")" & "*" & xSRg.Address 'Range("$B$2").Address
            End If
        End If
    Next

End Sub

Works like a charm!!! Thank you so very very very much!! :)
 
Upvote 0

Forum statistics

Threads
1,215,055
Messages
6,122,902
Members
449,097
Latest member
dbomb1414

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