Formula not updating - excel-formula

The usual answer to this question is to turn formulas to automatic. This, in my case, is not working.
The second usual answer is that there is some macro that is affecting the Excel settings. This is not the case with my problem (xlsx file).
Office 2010, my simple formula is not updating.
P.S. I copied the problem of Mr. DAN, however, the CTRL SHIFT ALT F9 worked for him but not for me so I only added the CTRL SHIFT ALT F9 in what I've already tried.
I have:
Researched this issue on the internet - all solutions easy to find do not address this problem
Pressed F9 (did nothing)
Pressed Shift-F9 (did nothing)
Pressed Ctrl-Shift-Alt-F9 (did nothing)
Pressed Ctrl-Alt-F9 (did nothing)
Turned calculation to manual and hit all combinations of F9 (did nothing)
Turned calculation back to automatic (did nothing)
Saved with a new name (did nothing)
Re-updated data on MainCopy (did nothing)
Selected the cell and hit F9 (did nothing)
Put my cursor in the box and hit enter (UPDATED VALUE CORRECTLY)
I cannot put my cursor in each box and hit enter, there are too many boxes. In
addition, this is creating a major error trap in a spreadsheet that needs to be correct. Is there some obscure setting that has been triggered in this file that is creating this issue?
The formula is:
=LOOKUP(2,1/(T15:T26<>""),T15:T26)
Everything else is updating in the spreadsheet. The cell in MainCopy has the correct value. The value displayed is the value before I updated the information on MainCopy. When I put new information in MainCopy, the value on this page stayed the same.
I expect the output to get value of last non-empty cell.

Related

I need a VBA code that after Userform enters date into a database, refreshes the cell the same way as going into it and pressing enter does

I have a long chunk of code that handles date data from a hidden datasheet, however anytime I enter a new date trough a userform, it writes it into the cell in the database in a format that for some reason can't be handled error free by my code chunk.
The problem is I need a sub to change the format (which is easy) but it does not actually apply the formatting unless I manually go into the datasheet, enter the cell and press enter.
I have searched and could not find a solution on how to do this in VBA, obviously this code is supposed to run automatic flawlessly plenty of times and having to manually go in an enter the cell defeats the entire purpose of the programming.
Sub Testing123()
MsgBox "run"
Workbooks("Excel Stock System.xlsm").Worksheets("DataNews_Events").Columns(8).NumberFormat = "dd.mm.yyyy hh:mm"
'something magic that actually automatically applies the format
End Sub

ActiveX textbox shows previous entry

Apologies for not showing my code but after much trial and error I'm thinking the issue I describe could possibly be a textbox property issue rather than coding error or ommission. The code itself works as it should but there is a phenomenom which frustratingly persists.
On a wsheet amongst a number of ActiveX controls I have a textbox and 2 images. They are used for a search function. As you would expect the textbox is for user entry and the images are for 'run search' and 'erase search'. I set the search text as a string.
My issue is when hitting either 'run search' OR 'erase search' the textbox momentarily shows the previous text string. I have set this previous string to "" all over but without success.
This is best observed when setting a search text which will knowingly fail.
The sequence is...
1) Enter 'XXXX' to search
2) Hit 'run search'
3) Search code executes
4) Prior to textbox narrative returning "XXXX not found" it momentarily shows the previous entry, say "AAAA", before returning the correct result.
How can this be prevented?
EDIT
With no response I posted this on Jon Peltier's site at https://peltiertech.com/forms-controls-and-activex-controls-in-excel/#comment-1481602
Kindly he tested and concluded "It looks like an ActiveX thing, and I guess you’re stuck with it."
From tests this phenomenon occurs even when selecting any cell, not only the image controls. In other words it is triggered as soon as the textbox loses focus. Arguably, because it is a momentary change it does not seem possible to trap the text.
I was experiencing a similar problem and raised a question myself, but managed to have more luck in getting some responses, see:
After setting ActiveX textbox to empty value, previous text briefly appears in box before disappearing again
Through the help of the responders I was able to create a work around using Application.SendKeys. Possibly one of the answers might be able to help you in getting around this issue.
For me personally Application.SendKeys was required as this overwrote the value in the text box and refreshed it meaning the previous value was no longer present. For completeness here is a snippet of the code I used:
'Select text box to update
Sheet1.userName.Activate
DoEvents
'Replace value with ""
Sheet1.userName.Application.SendKeys ("")
'Copy above for other textboxes on sheet
Sheet1.emailAddr.Activate
DoEvents
Sheet1.emailAddr.Application.SendKeys ("")
'Change text box currently active to force change values to take place
Sheet1.userName.Activate
I am selecting my text boxes one at a time then using SendKeys("") as a way to emulate the user deleting the current field in the box, after that I switch back to another text box as this is needed to force the refresh of the value.
Being able to force the text boxes to be blank after I was done with the values meant that there were no previous values that could inadvertently appear later on.
Thank you Skenworthy for your suggestion. Over time I kept returning to my issue but without success however your code has formed the basis of a solution.
I only had 1 textbox used as a search input plus 2 buttons, 1 to begin search and the other to clear.
My solution was to create a hidden dummy textbox and each time I wished to make a comment in the search textbox I would use sendkeys to the dummy box. However that was not the final code. Switching focus between the 3 controls became too complex given the type of potential user errors that could be made. So I abandoned the Begin search button relying instead on the Enterkey and the Clear search button.
Now each time I need to return a response message I use the code below immediately prior to clear the search textbox. It has consistently worked without flaw. So, a long time coming, my specific solution seems so simple in hindsight but thank you again for the pointer.
Sub RemovePrevText()
''' use dummy txtbox to clear old message from SearchInput
With Sheets(1)
.txtDummy.Activate
DoEvents
.txtDummy.Application.SendKeys ("")
End With
End Sub

Including text with quotes within a formula in VBA

I have a button coded to reset a spreadsheet with the following line in VBA:-
Range("F6") = "=IF(AND(vtype=TRUE,U41>0,vatable=FALSE),vatrate*100&"% VAT",IF(AND(vtype=TRUE,matchnew>1,vatable=TRUE),"VAT Exempt",""))"
When this button is clicked an error appears, it says that the % sign is an illegal character.
Please advise what is incorrect.
Try:
Range("F6") = "=IF(AND(vtype=TRUE,U41>0,vatable=FALSE),vatrate*100&""% VAT"",IF(AND(vtype=TRUE,matchnew>1,vatable=TRUE),""VAT Exempt"",""""))"
Excel is not objecting to % but to " without being escaped (with ").
As a test, I named a cell 'vatrate', then put =vatrate*100&"%V VAT" in another cell and it evaluated with no problem.
Put your cursor in the cell where this formula is
Click on 'Formulas' on the ribbon
In the 'Formula Auditing' section of the ribbon, click on 'Evaluate Formula'
That will allow you to walk through your formula one evaluation at a time so you can see exactly what Excel's seeing as it's evaluating it. That will tell you where it's going wrong.

VBA excel 2007. Create Button in cell

I'm creating a button with code
Set CreateButton = ActiveSheet.Buttons.Add _
(C.Left, C.Top, C.Width, C.Height)
where C is Cell object. Button appears not in cell but little upper.
CreateButton.Top is 107.25. And when I try to assign CreateButton.Top to itself, value is 114.75. What is going on?
It appears to be related to the margins. I changed it around and got the button to move its relative position by changing the top margin. Like you it only happened when adding the button while in page layout mode. In normal mode everything worked regardless of the margin.
You may be able to compensate with that information.

Force Refresh of "Last" Cell of the Worksheet

Pressing Ctrl+End in Excel takes you to the bottom-right-most cell of the worksheet.
If you delete the last rows or columns and save the workbook, this last cell gets updated, as well as the scrollbars.
I remember there was a one line VBA command that you could run that would do the update without having to save the workbook, but I can't remember what the command is - do you have any ideas?
I’ve found something that consistently works to delete those blank rows. You can tell when the “used range” excel is using is too big and is going to add extra blank rows when you use the scroll bar to the right and it goes beyond the last row of actual data when you scroll to the bottom. This will caused extra blank records to be added to the table when it is imported into SQL.
To get rid of them:
Select the entire first row under the last row of data. Hit Ctrl + Shift + Down Arrow to select all the blank rows.
From the Home Tab Select Clear and then Clear All from the Edit menu (picture of a whitish-grey eraser).
Right-click and select Delete.
Goto cell A1 first and then Save.
Press Ctrl + Home and then Ctrl + End (This should take you the correct last cell in the used range (above blank rows).
Click Save again.
Here is the answer:
Sub x()
ActiveSheet.UsedRange
End Sub
Run this and the last cell will be reset.
When none of the above works try this.
Select the unused rows and change the row height.
Now delete the rows and save.
Bingo!
Here's what I did... since none of the above worked (this time that is, which is sad cause this code was running beautifully then all the sudden xlCellTypeLastCell totally failed me.) This will only work if you hardcode the first cell of the region you wanna grab the last cell of... for example I was pasting data tables into a sheet of 12 - 40 columns and 60-90 rows... but since it was a paste, it always started in cell A79...
Worksheets("Data_Import").Activate
Range("A79").CurrentRegion.Select
A = Selection.Rows.Count - 1
B = Selection.Columns.Count - 1
Selection.Offset(A, B).Resize(1, 1).Select
Set DataEnd = Selection
I feel sad to NOT use the cool special cells thing, but alas, if it doesn't work! then I just can't use it. :C
p.s. - you could also throw in a
ActiveSheet.Cells(Rows.Count, 1).End(xlUp).CurrentRegion.Select
This solution works for Excel 2013, but may also work for most recent versions of Excel:
Choose the worksheet where you want to change the last cell, and delete any unused rows and columns
Click on File - Options - Customize Ribbon
Under Main Tabs, check the box next to "Developer", then click OK
On the Developer ribbon that now appears, click Visual Basic
In the upper-left corner, under Microsoft Excel Objects, click on the Sheet Name where you want to force a refresh of the worksheet's last cell
In the menu, click on Run - Refresh, then close the Visual Basic Window
When you hit Ctrl + End, your last cell should now be refreshed.
Check out http://dmcritchie.mvps.org/excel/lastcell.htm#MakeLastCell, found the link from a similar question.
Far from the forgotten one liner, but did solved the problem for me.
Alternatively;
Turn on manual calculation (to preserve references).
create new sheet.
Copy cells and Name of old sheet.
For some reason the code ActiveSheet.UsedRange alone did not work for me on Excel 2016 64-bit to force Excel to reset the last used cell.
This does work for me. Hope this helps.
Rows(25:415).Clear 'deletes contents and formatting
ActiveSheet.UsedRange 'resets last used cell
The solution to change row height to zero and saving worked.
Reopen, set row height to 12 and notice that End Home is no longer at the very bottom right of the worksheet.
THANK YOU. I have been working on this for over two years.
Jim Champaigne
Elkhart, Indiana
I'm not sure why everyone is making it so complicated. Just press Ctrl + PgDn.

Resources