I currently have the following in excel for other users.
The Number column does not change. Users will input values in Multiplier 1 and Multiplier 2 columns and they will get a value in Outcome column.
Is there an automatically way where the user can also input a value in Outcome column and the Multiplier 1 column will change?
Currently Number and Outcome column are protected, will I need to unprotect the Outcome column?
I recommend you use some VBA code using the Sub Worksheet_Change(ByVal Target as range) in the worksheet.
If the user enters a value in D2 it will put the formula "=D2/(A2*C2)" in B2
If the user enters a value in B2 it will put the formula "=A2*B2*C2" in D2
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Cells.Count > 1 Then Exit Sub
On Error GoTo LastLine
If Not Intersect(Target, Range("D2")) Is Nothing Then
Range("B2").Formula = "=D2/(A2*C2)"
ElseIf Not Intersect(Target, Range("B2")) Is Nothing Then
Range("D2").Formula = "=A2*B2*C2"
End If
LastLine:
Application.EnableEvents = True
End Sub
This can be done. Begin by noticing that your formula is so simple that you
Can easily solve for multiplier1 as a function of:
outcome divided by (number times multiplier2)
Next get tricky by adding a 1 pixel wide column that will contain your formula
for outcome to the right of (now an input not a formula) the original
outcome column.
Similarly add a 1 pixel wide col to the right of multiplier1 that contains
your new formula for multiplier1. Adjust data validation on original input
cells for multiplier1 and outcome to allow only one of the two to be
entered at a time (use isblank function appropriately in an excel custom data
validation rule for each cell).
Finally right align the two 1 pixel wide cells so that their calculated values
appear within the corresponding enterable cells when they are blank.
Yes it's tricky but it works.
Sorry this is just an outline but I have used this in an application and it
works great. No vba, so undo redo don't break. Try it you'll like it.
Related
I posted a question to Stack Overflow about creating a Excel Macro to add/subtract a value in a column from the previous column, then clear the current column.
Excel cell value update macro
The code worked find for years in office 2007, but no longer works in office 365 (2016/2019).
If F1 has a value of £100.00, and I type -50 into G1, F1 changes to £50.00 and G1 is empty.
Each cell in column F is changed by an amount entered into the row in column G.
In Office 365 versions of Excel this macro executes once then won't run again until I close an re-open the document. Has something changed about the way macros work that would cause this?
Edit:
Here is the code (attached to sheet 1), slightly modified from my previous question to work on column G.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim FirstNum As Currency 'Long is for number currency should help keep format
Dim SecNum As Currency
If Target.Column = 7 Then 'Only Runs if Cel l being changed is in column C, Might need to be Columns
FirstNum = Target.Offset(0, -1).Value ' Value in Column B
SecNum = Target.Value ' Value being typed in C
Target.Offset(0, -1).Value = FirstNum + SecNum ' Makes Cell B equal to difference of previous value and value typed in C
'MsgBox ("Difference Found") ' Just to display code worked Remove when confirm code works
Target.Clear ' Clears Value you typed
End If
End Sub
I don't have enough rep to do a comment...
Without seeing your full code it's hard to know. But if your code has
application.enableEvents = false
You will need to to set it back to True eventually. Or worksheet change events won't fire off until the workbook is closed and opened again
I think it is nothing wrong with Office 365...
In order to work as you explain, the code must look like:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim FirstNum As Currency
Dim SecNum As Currency
If Target.Column = 3 Then 'Only Runs if Cell being changed is in column C, Might need to be Columns
FirstNum = Target.Offset(0, -1).Value ' Value in Column B
SecNum = Target.Value ' Value being typed in C
Target.Offset(0, -1).Value = FirstNum - SecNum ' Makes Cell B equal to difference of previous value and value typed in C
Target.Clear
End If
End Sub
But, you must understand that this code works only for changing cells in column C:C.
The variant you received six years before worked only in the same column, but on vertical. I mean, changing of C2, it used to modify C1. But it had a bug. If you try modifying of C1 it will try to set an Offset of -1, row zero does not exist in Excel and returns an error...
I cannot understand how the event functioned at least once for ranges G1, F1. It could work only if some links exists in the sheet, or you adapted the code and in such a case the real used code will give us the possibility to analize and tell you, not supposing, where the problem is. I do not think it is a matter of Office version, but who knows...
It sounds like a formula would suffice. However a cell cannot refer to itself, you could try,
E1: =F1+G1
Where E1 is a new cell with the sum of F1 and G1, because you are entering its sign operator i.e. - or + the you can leave it as addition in cell E1. To use this for a column just drag from the lower left square on the cell E1 all the way down to the row number you want. This will refresh every time a value changes.
excel image
we have all added information in our heads and then written the results down,
for example a simple tally, yesterday I sold 10 apples, the day before I sold 5 for a total of 15, today I sold 5 for a total of 20, a simple equation we all do every day in our head without even thinking about it, the formula I believe would basically read: A+B=Bnew
where A would be the daily sale.
B would be the total sale
and Bnew is the new total.
how do I do this in excel without taking pages of running total lines, or fancy visual basic script.
I want to use at most 3 cell's
Cell-1 = changing variable, (the daily sale)
Cell-2 = the running total of all sales to which A1 will be added.
and if needed Cell-3 to hold the contents of Cell-2 like our memory holds it while we update the total.
a very simple math problem, but driving me nuts to try to get excel to do it, I have searched and searched but I don't even know the right question to ask.
thank you for your help
Given the restrictions:
No helper columns ("without taking pages of running total lines")
No VBA ("no fancy visual basic script")
"I want to use at most 3 cell's"
I think a remaining option is iterative calculation? I don't know, maybe someone else can think of a better solution. But regarding iterative calculation, here's how I've set my sheet up:
This uses two cells (ignoring the labels in row 1):
In cell A2, I have the formula =A2+B2
Cell B2 is blank (ready to have some number entered)
I then go to File > Options > Formulas > Enable iterative calculation > Change "Maximum Iterations" to 1 > OK
Any notifications regarding circular references should now disappear, and if I put a number in cell B2, cell A2 updates in the manner you described in your post. Hopefully, you can replicate this on your machine too.
The thing to note is the iterative calculation setting you'll change is application-wide, so I believe it affects all other workbooks. Something to keep in mind.
If your setup looks like this in Sheet1:
then a small vba macro in the worksheetmodule from Sheet1 should do the trick:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$2" Then
Range("B2").Value = Range("B2").Value + Range("A2").Value
End If
End Sub
This subroutine will run after every worksheet change. It will check if the change was in cell A2. If that's the case the value in A2 will be added to the value in B2.
Assuming you're okay with a small amount of VBA code, you could try putting the code below into the worksheet module for the sheet where you're entering the data:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
' Assumes "daily sales" are entered into cell B2 and that "running total" is in cell A2
If Not (Intersect(Target, Me.Range("B2")) Is Nothing) Then
Me.Range("A2").Value2 = Application.Sum(Me.Range("A2").Value2, Target.Value2)
End If
End Sub
(Pressing Alt + F11 concurrently should open the editor, you can then find worksheet modules on the left).
If you then enter a number in cell B2, then cell A2 should update in a cumulative manner. If you enter a number in a cell other than B2 or A2, you should find cell A2 doesn't update (unlike the iterative calculation approach). We use Application.Sum instead of + operator to avoid Type Mismatch error, if either A2 or B2 contain non-numeric data.
Try it, see if it does what you're after.
Edit:
If you have multiple rows, you could try something like below.
Private Sub Worksheet_Change(ByVal Target As Range)
' Assumes "daily sales" are entered into column B and that "running total" is in column A
If Target.Column = 2 Then
Me.Cells(Target.Row, "A").Value2 = Application.Sum(Me.Cells(Target.Row, "A"), Target)
End If
End Sub
I need to ad the next sequence number in Column A automatically when I fill enter the next value in Column B. This sounds confused. Just see the snap so you will get the clear picture.
This should be done without usual dragging option. Is there any way
Make the Value of A1 equal to 1 and then from the A2 use the formula:
=IF(B3<>"",A2+1," ")
Drag this formula for the whole column.
In my solution I have a drag, but it is to define the formula for each of the fields. (I'm not sure if is this you are trying to avoid when you say
without the usual dragging option
)
You may achieve this using macros. Formula will increase the file size and processing time.
Right click on the sheet name on sheet tab-->select view code-->paste below code--> save file as macro enabled workbook.
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo step
If Target.Column = 2 And Target.Value <> "" Then
Target.Offset(0, -1) = Target.Row - 1
End If
Exit Sub
step:
Exit Sub
End Sub
You can also do this without using macro and formula:
Type first 2 value to the cell to establish the pattern
highlight the cell range
Under Home tag -> select Fill -> choose Series
Follow the image and Select OK
If you convert your table to a List ("Table") and use a formula for the first column, that formula will "auto-extend" as new values are typed in under "Item"
Is it possible to select a specific cell in a range that changes depending on what cells are highlighted.
So if i Had;
Range("C1").Value = Application.WorksheetFunction.Sum(Selection)
It would sum the entire highlighted area and put the value in C1. Is it possible to only select some cells in the highlighted area. I know it sounds dumb, i realise can just highlight the cells i need but this is just a simplified version of the problem I've got.
What i'm asking is, is there a way in code to say;
"In the highlighted range, select the cell that is 2 columns to the right and 4 columns down from the top left boundary of the range"
Thanks
The Code for your question:
"In the highlighted range, select the cell that is 2 columns to the right and 4 columns down from the top left boundary of the range"
Selection.Cells(1).Offset(4,2).Select
in your case being Selection a Range you can use its methods/properties:
Range("C1").Value = Application.WorksheetFunction.Sum(Selection.Cells(5,3))
since Cells(5,3) reference a cell 2 columns to the right and 4 rows down offset the selection top-left one
You may be able to use the Worksheet_SelectionChange Event and examine the Target reference.
For example paste this test code into some sheet class:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "A1" Then Exit Sub
Range("A1").Value = WorksheetFunction.Sum(Target)
End Sub
Something like this - obviously you're going to have all kinds of checks in there for Errors and the likes.
I'd also look at some way of disabling the code since you're going to have Events firing all over the place. Depends on your requirements.
Looking for a formula for specific range of values to a reference range on another sheet...
i.e. if cell A1 sheet 1 contains a specific value, then i would like it to find that value on column A of sheet 2 and result with equivalent row value of column B
I have a range on sheet 2 showing temperatures in column A with equivalent adjustment values in column B to go with each particular temperature.
I would like a formula that automatically fills in the temperature adjustment value into cell K23 on sheet 1 when I input the temperature into cell J22 (to be more specific)
Thanks for any help in advance!!!!
Here is some 'bare bones' code with some main concepts for you to start work with.
You will notice that you have received a number of downvotes for your Q. This is likely becase the spirit of this site is for you to demonstrate that you have made some attempt and/or research to 'help yourself' before posting your Q. For this reason I have not included any explanation.
Private Sub Worksheet_Change(ByVal Target As Range)
If Application.Intersect(Target, Range("J22")) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
adj = Application.VLookup(Target.Value, Sheets("Sheet2").Range("A1:B10"), 2, False)
If IsError(adj) Then
Range("K23") = 0
Else
Range("K23") = adj
End If
End Sub