I have my userform which contain 2 textbox for the target value and the actual value.
TextBox1 will be my target value while TextBox2 will be my actual value.
When the actual value is being key in, the userform will look into the worksheet "Target" and check whether is there any amount need to top up to reach the target value or not.
Here will be my data inside my "Target" worksheet:
Cell G1:S1 will be my target value while F2:F19 will be my actual value.
If textbox2(actual value) equal to 20A and my textbox1(target value) is 5S,
When go to the next field, textbox3 to fill in others data, it will show a pop up message to alert user to add 50ml conpac in order to reach the target value.
I have been research through webpage but seem like index match does not help in this condition. Please help.
Thank you
If you create the following named ranges: G1:S1 named "Target_Value", F2:F19 named "Actual_Value" and G2:S19 named "Additions" then:
=INDEX(Additions,MATCH("20A",Actual_Value,0),MATCH("5S",Target_Value,0))
Will return 50. You can put this in a cell somewhere or modify it to work in VBA (using Application.Worksheetfunctions)
Related
I have an excel file where each cells shows value when button "Calculate" is clicked.
So, If any cell gets an error, I have to give another value into the main cell.
Is it possible to put predefined value in a input cell by VBA when error occurs in other cell? Input cell should also be free for manual entry.
If I understand correct, a range of cells is filled when the calculate button (a marco) is pressed. If anny of these cells in this range has an error, the main cell (whatever this is) has to get a different value..
Question 1: what does the main cell contain when there is no error?
Question 2: how is the range filled? By the macro?
Assumption: if Q2 is correct, then the macro should handle the error and give the main cell a different value....
I am trying to use some sort of trigger to allow the user of this sheet to take an outputted value (through an algorithm I created) and transcribe it into another sheet.
The cell that it should transcribe the value to will be determined by taking the row name and column name from the user.
In this example, the user would insert X and Y as their row name and column name respectively. Once they click the trigger button (does not have to be a button, I am willing to use any type of trigger, but I assume there must be one in order for this to work), the value in the "Value (Rounded)" labeled cell will be transcribed to the corresponding cell:
This cell is where I want to insert the value.
The goal of this is automation. Ideally the user only needs to input the row name and column name and press a button (or any other trigger), which will transcribe the value into the other sheet.
Does this have to be VBA? This can be done with a pretty simple formula.
Assumptions:
The input sheet is named Input (change all references to Input to be the actual name of that sheet)
The row name is in cell B1 (change Input!$B$1 to be the actual row name entry cell)
The column name is in cell B2 (change Input!$B$2 to be the actual column name entry cell)
The Value (Rounded) cell is in B4 (change Input!$B$4 to be the actual Value (Rounded) cell)
In cell B2 of our Output sheet, put in this formula and then copy over and down:
=IF(AND(Input!$B$1=$A2,Input!$B$2=B$1),Input!$B$4,"")
Adding a button can be done by creating a shape (rectangle or any other), right click it and select "Assign Macro". There you can select a macro which should be carried out after clicking that shape. One note though, the macro needs to be a "public sub".
You need to use event macro within the SHEET code (not module code). Here are two examples of how to get if a cell is changed or if a double click happens, both on specific cells:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("E3")) Is Nothing Then
'Do something of Range("E3") has been double clicked
'(Basic Example)
'Range("G3").Value = "Range("B3").value
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
'If a cell has chanced...
If Not Intersect(Target, Range("B3")) Is Nothing Then
'Do something
End If
End Sub
I am trying to populate a VBA userform combobox with a named range, and I want the text value to display in the combobox for the user to select, but the value I want returned is the cell reference to the initial named range. That way it would point back to the named range, and if I change that text, it would automatically update all the references I have on the sheet that were entered by the form.
Right now I can get the named range to populate the combobox by iterating through the range, and using an .AddItem to give it the textual value, but then it just dumps that textual value into my spreadsheet, when instead I would like it to have the cell reference from the range that populated it.
The easiest way to do this is to create an Array(X,2) X being the number of items in the array. Then you put the String you want to display in Array(1,1) and the data you want in Array(1,2) then simply populate the combo box like normal. When you and use the array to reference which item they choose. They choose item 8, you know it is Array(8,2) If you need more help please post some code.
So, after more research it would seem that I am unable to directly accomplish what I want with the combobox. I ended up just looping through the range to fill the combobox with the textual values, and then when I submit the form, I looped through the same range of values, checked it if the submitted value matches one from the range of values, and if it does, then return the .Address instead of the .Value, and that gave me the cell reference I was looking for. Too bad the combobox doesn't work more like a real html select menu, it would have made my life a little easier, but in the end I was able to make it work, it just isn't as clean as I would have liked.
I've a problem with this VBA macro.
Sub demoChangeText()
Application.Range("B2").Value = "Overidden text"
End Sub
My test is here. To run this macro, open it in Excel, press Ctrl+F8 and choose demoChangeText.
As the result, this macro changes the value of cell B2 (the text displayed to us) but clear its formula. I need to change B2's value BUT also need the formula to be remained.
So my question is How to change the display text of cell without changing its formula?
UPDATE
I ask this question because I'm trying to solve this problem
I'm not sure if this will help, as it is a bit hard to tell what your underlying requirement is, but here goes anyway:
Several things affect the display of a cell:
the entered value, if its a constant
the result of a calculation, if its a formula
the format of the cell
the conditional format(s) of the cell, if any
In the example sheet provided you have a formula of =ROW()&COLUMN() which returns a string result of 22
You can make this display something else by applying a cell format,
eg a format of 0;0;0;Ov\e\r\ri\d\d\e\n t\ext will display any string value as Overridden text
This can by applied with VBA with
Range("B2").NumberFormat = "0;0;0;Ov\e\r\ri\d\d\e\n t\ext\s"
or
Range("B2").NumberFormat = "0;0;0;""Overridden texts"""
I have been reading around for a bit and reached the ask SO point. I have a drop down selector in excel that lets me change names and when the name is changed, the value in "C3" is changed (c3 references another cell on another sheet if that matters) and when the value in "C3" changes I want a pivot table on another sheet (sheet6 for now) to update its filter on territory id to reflect the new value of "C3".
It sounds like an event to me, so I went digging around and found out VBA has events (yay!), but I have been unable to get my event to actually do anything. The code I have there works when I run it as a macro, but I would really like it to automatically run everytime the value in cell "C3" changes.
Here is what I am trying so far:
Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Sheets("Current Status").Range("C3")) Is Nothing Then
Sheets("Sheet6").PivotTables("PivotTable5").PivotFields("territory_id"). _
ClearAllFilters
Sheets("Sheet6").PivotTables("PivotTable5").PivotFields("territory_id").CurrentPage _
= Sheets("Current Status").Range("C3").Value
End If
End Sub
Update: I have found that if I put the above code in the sheet section (sheet 2) instead of in a new module I can get it to run if I physically enter the code and then hit enter. Now I am wondering if there is a way to make it do it without me having to manually enter the value and hit enter. I just want to be able to use my drop down menu to select a new name and when the value in c3 changes due to the drop down selector update the pivot table.
Thank you as always SO.
The problem is that C3 is not actually changing, because it's just formula reference that is updating. Is the "drop down selector" on a form or based on data validation and in a cell?
If it's based on a cell, set your target to be the target cell, not C3 -> because C3 is just a
formula reference, and your drop down cell is the one actually changing.
If it's based on a form, but code in the on_change event of the form control.