Accessing ActiveX textbox value from cell formula - excel

I cannot post my code because it is company property, but the issue is that I would like to enter a cell formula so that it automatically updates when particular other cells change.
I have two columns, one for prices in USD and another for another currency. The other currency column is a simple "=SUM..." but the currency conversion to USD is always changing, and the prices are large enough that these changes matter. As such, I have the user enter the conversion value in the activex textbox, and I want to set the formula of the USD cells to be the price in USD, so obviously I need to get this conversion value, but I cannot just type in the textbox name, that does not work.
I am using VBA, but I would like to enter this directly into the cell as "=FORMULA", where formula contains the activeX textbox value, so that it automatically updates.
As far as I have found in VBA, if I want to assign a formula to a cell, I have to do so within a sub or function, so I have to call the sub every time I want to update the cells, but I want this to be as automatic as Excel is for other cell formulas.
I have been playing with Worksheet_Change and considered worksheet_open but have had other issues. For example, there are many different cells that could change that I have to monitor for change, and I cannot simply monitor the price column in the other currency for change because when cells update from a formula, Worksheet change does not show those cells as having changed.
Maybe this is as simple as setting the cell formulas on worksheet_open, but I also have not had luck with getting cell.formula to even work. I could discard the textbox for a regular cell which would totally solve this problem, but I also have a textbox_lostfocus sub that I need to run, and I don't know how to do that for a cell.
Sorry for the long post, in summary, how can I assess a textbox value for use in a cell formula ideally without using vba?

This is what linked cells are for. You link your ActiveX textbox to a cell. The cell value then gets updated once you update the value of your textbox. You can reference this cell in your normal excel formulas. See here for a tutorial: https://analysistabs.com/vba-code/activex-controls/textbox/

Related

in excel, a formula with no references to other cells changes all cells value when editing one of the cells

if i use a formula like this, which doesn't have any reference to any other cell:
=CONCATENATE(DEC2HEX(RANDBETWEEN(0,4294967295),8),"-",DEC2HEX(RANDBETWEEN(0,42949),4),"-",DEC2HEX(RANDBETWEEN(0,42949),4),"-",DEC2HEX(RANDBETWEEN(0,42949),4),"-",DEC2HEX(RANDBETWEEN(0,4294967295),8),DEC2HEX(RANDBETWEEN(0,42949),4))
and paste it to multiple cells on a sheet, then simple double click a cell and hit enter (no changes), all the cells that have that formula change value.
Anybody know why?
Excel has the concept of 'volatile functions'. These include RAND , NOW, TODAY. Volatiles are recalculated when the book is opened and whenever a cell is edited.

Trying to add formula directly to a cell in VBA and it disappears?

I have an input form where someone puts in numbers and clicks submit so it records on a table. I realized I want to have one cell on the input sheet calculate a percent automatically instead of having to calculate it manually. The problem is that every time I enter the formula and then use the clear macro, the formula disappears instead of just the value within. I have other cells with formulas that this does not happen to so I am assuming there is some way to fix it and make it like the others. In the code it is using
Range("ccmcocc").ClearContents
just like the others with formulas.

VBA Pop-up Message Code

I am trying to figure out how to display a pop-up if the value in a cell exceeds a certain value.
I have a worksheet that tracks the absences of employees per day. The names are in column A while the dates are in rows D to AH. I have a formula in D15 that counts the absences of employees on say D33 to D50.
What I'm looking for is a code to display a message box if the value of cell D15 exceeds 4. Then have the pop message applied from D15 to AH15. Then I want to restrict the message per cell. I also need to have it set up for E16 to AH16.
Then how do I apply it for each month but all in the same worksheet?
You can do it 2 ways at least:
Use VBA: Add the on worksheet change event to the worksheet (http://msdn.microsoft.com/en-us/library/office/ff839775(v=office.15).aspx) and add an if statement to check the changes in the cells you need e.g. D15. In response show the message. This has 1 setback - you will not be able to do CTRL+Z (undo) operations as when VBA executes it cancels the log of modified operations.
Simply add a column with a formula asserting the condition in D15. In response may the formula simply show text with the message. You can also use conditional formatting to change the cell background (e.g. to red).

Excel calculates formulas based on wrong dynamicly defined sheet

I have the following formula on various sheets in an Excel workbook:
=SUM(SUMIFS(INDIRECT(CONCATENATE("'",REPLACE(CELL("filename"),1,FIND("]",CELL("filename")),"")," HR","'!$e:$e")),INDIRECT(CONCATENATE("'",REPLACE(CELL("filename"),1,FIND("]",CELL("filename")),"")," HR","'!$q:$q")),I$13,INDIRECT(CONCATENATE("'",REPLACE(CELL("filename"),1,FIND("]",CELL("filename")),"")," HR","'!$j:$j")),{"שעון","בתפקיד","עבודה מהבית"}))
the formula takes the name of current sheet, concatenates the string " HR" to it and goes to a range of cells in sheet named as the concatenated string.
It performs a few calculations on the data there and returns the value.
For some reason the cells in different sheets that contain the "same" volatile formula show me the values that would come up in another sheet.
To see the right value I must enter only one of the formulas boxes in a relevant sheet, press enter and the evaluation turns to be correct.
I tried formula evaluation and theoretically it shows me the right calculation process on every sheet.
Any suggestions? Could it be some evaluation issue that is not related to formulas correctness?
You expect CELL to return information on the current cell when no reference is given, but it does not. CELL returns values based on the ACTIVE cell -- the cell that is active at the time of the calculation. Every time the cell recalculates, it will look at the active cell at that time, which may be on another sheet.
To see this in action, use the formula =CELL("address")&" "&TEXT(NOW(),"hh:mm ss") Since NOW is volatile, the cell will be recalculated every time you edit a cell. Edit any other cell, and you will see the address of that cell and the time it was calculated.
You will almost always want to include a reference value, eg CELL("filename",A1) To get the expected behavior, you'd just use a relative reference to the current cell.

Why is cell losing formula after initial calculation? - Excel 2007

I have an excel sheet that is being fed data from a userform. Certain cells auto update based upon when certain cells on the Home page or Setup page change.
On the setup page, cell H1 references cell Home!B15 which is control sourced to my userform. It takes in a sales rep name.
Cell H2 has the following formula
=IF(ISERROR(VLOOKUP(Home!B15,D2:E243, 2, FALSE)), "", VLOOKUP(Home!B15,D2:E243, 2, FALSE))
This works fine!
In cell Home!B16, I have the following formula
=Setup!H2
For whatever reason, it will populate the correct value one time. Once I select a different sales rep in my userform, it loses the formula, and keeps the first value.
My question again: Why is my cell losing it's formula after taking on its first value?
I have encountered the same issue with a userform in VBA/EXCEL 2010. It seems when you change a value in the form that affects the value in a calculated cell, the formula in that cell gets replaced with a literal value. Pretty frustrating.
The best I could do for a workaround it to store the formulas that get lost in another location (in a dictionary object, for example) and then when I close the form I use VBA to overwrite the [new] literal value(s) with the formula(s) that were in those cells to begin with.

Resources