=IFERROR(VLOOKUP("Processed Units Forecast",'IB ALPS'!$A$59:$K$1000,MATCH(Date1,INDEX('IB ALPS'!$1:$1048576,3,1):INDEX('IB ALPS'!$1:$1048576,3,11),0),FALSE),"N/A")
Hello, so I'm having an issue with this formula. I have a macro that deletes some of the DATA on the IB ALPS sheet. By the time the macro is finished, all of the referenced cells/ranges are fixed, but somewhere in the middle it creates a REF error # $A$59:$K$1000(because of that split second where the cells are deleted). How can I stop excel from editing the function in that 1 second down time that the macro has, or how can I edit the function to keep referring to that range without immediately adding a REF.
If you have the ability to edit the macro, you can temporarily disable calculation for your sheet while deleting the cells:
ActiveWorkbook.Sheets("IB ALPS").EnableCalculation = False
' Some code that deletes rows goes here
ActiveWorkbook.Sheets("IB ALPS").EnableCalculation = True
This should prevent the functions on that sheet from thinking that anything has gone wrong. See the Microsoft documentation on this property for more information.
Related
I have created a spreadsheet which uses the Worksheet_Change feature and the code associated with that works very well. I can stop it firing unnecessarily when inside the module by using Application.EnableEvents = False.
However, while I've created a form to enter data directly into the next available row (again, that works fine in terms of entry) it doesn't cause the formulae in the sheet to calculate (even though auto calculation is on and re-enabled within the module). If I manually place my cursor in the row, hit F2 and simply press enter, everything then fires up.
I have tried to enter data directly into the cells, but of course the Worksheet_Change feature then kicks in again and the cursor isn't simply moving to the next adjacent cell ....
I've tried to check firs for any direct entry with the code below and if it looks like the user isn't entering directly into the cell, the Worksheet_Change is disabled:
Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo eventhandler
Sheets(1).Range("a1").Select
LastCell2 = Sheets(1).Cells(Rows.Count, "A").End(xlUp).Row
Dim intersection As Range
Set intersection = Intersect(Target, Range("A3:F" & LastCell2))
If intersection.Row = LastCell + 1 Then
Exit Sub
End If
Application.EnableEvents = False
The code above is simply checking to see if data is being entered into the next empty cell and if that's the case I want it to just exit there but it isn't working.
So I actually have 2 problems :
the first is why this formula isn't triggering after entry via a vba form - I've used INDIRECT since there are other macros that delete rows by moving the remaining cells up and that was causing the count in the $A$3:$A$500 to reduce to $A$499 and then 498 etc - the addition is done depending on the system date and the transaction date so I get a current value and a future value using a standard sum statement:
=AD1-(SUMIF(INDIRECT("$A$3:$A$500"),"<="&TODAY(),INDIRECT("$E$3:$E$500")))+(SUMIF(INDIRECT("$A$3:$A$500"),"<="&TODAY(),INDIRECT("$F$3:$F$500")))
The second is why I can't enter data directly into the spreadsheet and trap the fact that I don't want it to do anything and simply allow the user to hit enter and move to the next adjacent cell to the one they just entered data into.
Is this a lost cause and am I trying to do too much here? I'm relatively new to coding and teaching myself so apologies if the standard and style isn't to everyone's taste.
Thanks in advance for any replies.
I am trying to write this VBA so that if cell(U5) = "YES" then range(B5:T5) are locked else range(B5:T5) remains unlocked. Similarly if cell(U6) = "YES" then range(B6:T6) are locked else range(B6:T6) remains unlocked and so on. Unfortunately my codes are not running and I am unable to find the error! Please find my mistake!
From your narrative, I've gathered that you only have to do anything if the values in column U are changed and then only to the cells in B:T on the rows where U has changed.
There is no indication as to what should happen if the cells in column U are neither Yes or No. I've left an area for you to deal with that if you want to.
You were using i + 21 in the column number parameter of cells. This means that the first time the loop goes through it is U5. On the second iteration it is now V6; on the third W7, etc. This is not what your narrative states so I followed the narrative's instructions and assumed a simple coding error. This also means that (if you had run through the code previously) you may have inadvertently 'locked' the wrong cells. If that is the case, you might just want to start on a new worksheet and delete the one you had been working on.
The Worksheet.Protect method has an optional parameter for UserInterfaceOnly. When set to True, the user is restricted by a protected worksheet but no VBA code is similarly protected. This means that you do not have to .Unprotect the worksheet to run your code. I've added a 'helper' sub procedure; run it once and then you do not have to Unprotect and reProtect the worksheet.
If you choose not to use UserInterfaceOnly protection, move the .Protect and .Unprotect statements outside the loop so that they are not performed for each row.
I've researched this to death and feel like I'm the only person it's ever happened to.
I have some VBA that:
Creates a copy of 3 sheets to a new wb
In the new wb converts to values, deletes objects (shapes and controls) and all but 3 ranges
Opens an existing third file and sets the contents of three ranges in that to match the new wb
Closes the existing file (saved)
Closes the new wb (saved)
Gives a message box saying complete
At the end of all this, something weird happens with the state of the windows. The selected cell does not appear selected. If I try and click a control afterwards, it selects the object (hence users could drag them). It shouldn't and this is the big problem.
I've tried selecting a cell through code, it throws an error. I had limited success by forcing drawing mode off using Call CommandBars("Drawing").Controls("Select Objects").Execute and activating a specific sheet & selecting a cell. However, even then if I even click on a few cells afterwards, the next time I select a control it will select it as an object rather than click the thing.
I have no idea why and can't find anyone who's seen this before.
Any ideas on what I can do?
Thanks,
Basil
I didn't figure it out entirely, but I did find a fix. Hopefully it works for anyone else who finds this problem.
At the end of the code I added this:
ActiveSheet.Shapes.Range("ctrlExportPrices").Select
ActiveSheet.Range("B8").Select
So it forced a control on the sheet to be selected, and then a cell.
The next time I select the control manually, it clicks it rather than selecting the drawing object.
I have a question about freezing certain cells. But first let me explain the situation.
I have made a search box in my excel sheet and when you search for a letter or word; the results show up in cells below the search box. Now I want to freeze those cells, so that wherever I go in my sheet. I can always use the search box and see the results.
The cells for the searchbox and results are B2:B25. Those are the ones I want to freeze. Also the only sheet I want to use this on is the sheet "Reading". On the rest of my sheets I do not use a search function.
So my question(s) is : Do I need to put the code inside a module or on that sheet, and how do I do this?
Now I have tried the following
Range(Cells(2,2), Cells(25, 2)).Select
ActiveWindow(or maybe Reading?).FreezePanes = True
Inside a module. But it did not work and I do not know what else to do.
Any help is much appreciated! Since I am very new to VBA.
Almost there. Problem is that the 'range' and 'cells' needs to be directed to the 'Reading' sheet, like so:
Sheets("Reading").Range(Sheets("Reading").Cells(2,2), Sheets("Reading").Cells(25, 2)).Select
ActiveWindow.FreezePanes = True
but if it always is B2->B25, why not use:
Sheets("Reading").Range("B2:B25").Select
ActiveWindow.FreezePanes = True
This should work. Select is not very desirable, because it is very slow, but in this case, you need to (as far as I know).
EDIT
BTW, you can do this from within a code module or from within a sheet, but if you choose to do it from within a sheet, you cannot select another sheet. So just use the range.
EDIT 2
whoopsy, typo corrected. 'Sheet' should have been 'Sheets'
I have a pretty large Range (10,000 rows, 10 cols) that I fill line by line on an everyday basis. I also have a smaller Range (366 rows, 5 cols), in which, for every cell, I run a macro. That macro does pretty much what DSUM or SUMIF do, but with multiple criteria.
The problem is that after having this fancy stuff implemented, I can't fill my stuff decently, coz on every cell I fill the macro is ran dozens of times, and every times it loops hundreds, taking around 5 seconds to let me fill the next cell.
I'd like to be able to prevent the smaller range to be updated (or the macro not to be ran), so I can fill it all normally, and then press a button to update everything.
You will need to lock the target range (setting the Locked property of the Range to true). Then you will need to protect the sheet by calling the Protect() method of your worksheet. Below are examples of how to lock and unlock the cells A1:A4.
Locks:
Sheet1.Range("A1:A4").Locked = true
Sheet1.Protect()
Unlocks:
Sheet1.Unprotect()
Edit: After re-reading the question, it seems as though the OP is using the Worksheet_Change event. To which I have one word:
STOP
Just put in an ActiveX button into the sheet, and then assign a macro to that, as described here.
The Worksheet_Change event is fraught with peril. Beware ye who enter, for there be dragons.
Well there's this:
Application.Calculation = xlCalculationManual
But that stops all recalculations, until you rest it to automatic or explicity call for a Recalc. Is that sufficient, or do you need more?
If you need to limit the recalc restriction to only prevnting specific macros from executing, then the following:
Add a "Global IShouldNotRun as Boolean" to your macro(s)
Your macro(s) should check the IShouldNotRun value and exit if it is true.
write another macro that toggles this global.
Have whatever is doing you data loading call the routine to set the global to True.
Reset it after you are done loading and call Calculate, CalculateFull or CalculateFullRebuild.
I don't have ecell on my computer so I cannot check the exact path, but as far as I remember after going to Tools/Options menu there is a tab 'calculation' or 'computation' where you can disable the automatic formula recalculation.