Prevent Macro Interruption
Aug 8, 2007
I have a macro, that when running needs to display certain sheets that should be hidden again when the macro is done. I solve this by using the code
Sheets("Sheet1").Visible = True
'macro code
Sheets("Sheet1").Visible = xlVeryHidden
But what if the macro fails? Or if the user ends it by pressing Esc? Then he will be able to see the hidden sheet. Is there something I can write in the code that makes the macro hide the sheet, then show the error message?
View 5 Replies
ADVERTISEMENT
Nov 18, 2009
The code itself functions as desired however i am getting the vba message "code execution has been interupted". However if i comment out the line
ActiveSheet. Range("Y6:BC6").Delete Shift:=xlUp. Then all is well - so i'd say that is the culprit.
Sub Test()
If Left(ActiveSheet.Name, 5) = "query" Then
Dim intRow As Integer
intRow = ActiveSheet.Range("Y4").End(xlDown).Offset(1, 0).Row
If intRow > 25 Then
ActiveSheet.Range("Y6:BC6").Delete Shift:=xlUp
intRow = intRow - 1
Else
End If
' Runner 1
ActiveSheet.Range("Y" & intRow).Value = ActiveSheet.Range("A5").Value
ActiveSheet.Range("Z" & intRow).Value = ActiveSheet.Range("M4").Value...................
View 6 Replies
View Related
Jun 21, 2006
I have a macro that opens various files (via a loop) and then goes to each worksheet (via another loop) and looks through each row of data (a third loop).
Each worksheet can have over a thousand rows of data. Once I hit the button for the macro to run, it runs without any error messages, but it seems to take forever.
When I hit escape twice to interrupt the macro and then press the 'play' button, it zips through and finished running the macro really quickly. The interruption point is generally somewhere within the third loop.
It's almost as though it falls asleep and I have to wake it up.
View 9 Replies
View Related
Mar 14, 2007
Prevent saving and allow only through Macro
I am contracting an excel template and need to stop users saving the file using Save or Save As. I am able to do this by using the private sub below:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Me.Saved = True
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Cancel = True
End Sub
I also understand that by switching to Designer mode you can save the file and once re opened designer mode will be switched off. What I need is to allow saving using a macro, is there a code that I can insert in the macro to switch designer mode?
View 9 Replies
View Related
Feb 21, 2002
Is there any way to write a macro which can prevent computer illiterate users from saving their files EVERYWHERE??
View 9 Replies
View Related
Nov 14, 2008
I need a line of code so that when I hit commandbutton2, the Private Sub Worksheet_Change(ByVal Target As Range) event macro on the same page DOESN'T run. The button clears certain lines, and when it runs the change event it ends up in an error, and I don't need it to run when hitting the commandbutton.
View 6 Replies
View Related
Feb 9, 2009
Is there a way to prevent access to the code of a macro? I am interested in sending out some macro's, but would prefer that the user only be able to run them, and not be able to access the code via the edit button. Curiously, there have been occasion's where I wanted to edit my own work, but the edit button did not function, so I had to exit and start over to proceed. From this I'm guessing there must be a way.
View 2 Replies
View Related
Jan 11, 2007
I would like to write a macro that performs the following function:
I have a value in cell A1
In cell A2, I have the formula "=A1"
I want to make it so that cell A2 can never be directly changed; the only way to change the value in A2 is by changing A1. A2 should always equal A1.
I want a message box to pop up and alert the user whenever they attempt to modify A2, instructing them that if they wish to change A2, they have to change A1.
I had written this macro, and it kinda does the trick:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("a2") Range("a1") Then
MsgBox "text goes here"
Range("a2").Value = Range("a1")
End If
End Sub
When I attempt to change cell A2, I get the MsgBox popup and it works how I want it to. However, when I alter cell A1, I get the same popup before cell A2 updates (to be precise, the popup occurs after I click another cell). I would like this to be immediate and without a MsgBox.
View 9 Replies
View Related
Apr 29, 2008
I have a macro that is run by clicking on a macro button. The macro copies the data from Sheet1 and pastes it in another sheet, Sheet2. I added some conditional formatting that colors certain cells red if others are blank on Sheet1. I would like to add some code to my macro that will not allow it to copy and paste from sheet1 to sheet2 if there are any red cells in the range.
View 9 Replies
View Related
Aug 6, 2008
I have an add-in that I'm passing around to my users, and though it has 8 or 9 subs, it only has 2 that they need to see. However, I'd rather not relegate all of the code to a single module, as there is quite a bit of it. I'm aware that I could change all the subs to functions, but they would still appear in the UDF list, and this would also be confusing to the individual responsible for the upkeep of these macros (and I'd have to rework the code a little bit).
I'm just asking if there is any direct way to do this, before I go to the trouble of making a lesser workaround. Google seems to think no, but "don't show macros in list" isn't a very solid search.
View 9 Replies
View Related
Aug 5, 2009
I'm using the following code to delete columns:
Dim rng As Range
Dim i As Integer, counter As Integer
Set rng = Range("1:1")
i = 1
For counter = 1 To rng.Columns.Count
'If cell i in the range contains an "x",
'delete the column
If rng.Cells(i) = "x" Then
rng.Cells(i).EntireColumn.Delete
Else
i = i + 1
End If
Next
My problem is that I have cells in other worksheets linked to the worksheet that is running this macro and everytime I run it, I get a handful of "#REF" errors. I think this problem might be solved if I could simply delete the contents of the column rather than deleting the entire column. How can I modify my code to do this?
View 4 Replies
View Related
Nov 23, 2009
I'd like to know if there is a change event that only occurs when a target cell is changed by the user, but does not occur when i'ts changed by a macro. nfortunately, the Worksheet_Change event occurs in both cases.
View 2 Replies
View Related
Sep 8, 2006
I have to issue template workbooks to people for budgeting purposes.
Within the workbooks are various numbers of worksheets pre -formatted and ready for these people to enter data.
Some of the data in the worksheets is important to them as individuals but not to me so I have a series of macros that lift the information from the worksheets and put it into a worksheet more specific to me.
Because the users are on the whole not that good with Excel I have put in easy to use look up tables and various proctections to stop them adding or deleting rows or columns as this plays havoc with my macros.
There is one thing I have "so far" been unable to do and I wondered if anyone could help.
Is there a macro that I could put somewhere in the workbook which would detect when someone tried to cut and paste and would either put up a message box or stop them doing this?
The reason being they are cutting from one row to another and this is messing up the calculations which are protected.
Is there also a way to stop them changing the name on the sheet tab in the smae way?
View 9 Replies
View Related
May 26, 2009
Is there a way to prevent the Workbook_SheetChange event macro from triggering when I run Excel's Solver?
The solver goes through 100 or so iterations changing multiple cells each of which seemed to trigger the Workbook_SheetChange event. If there was a Solver Run event, I could turn off application events, but as far as I know such an event does not exist.
View 9 Replies
View Related
May 3, 2014
I am trying to use the simplest code possible (being a novice) to execute a macro which makes a copy of Cell A1:A4 and paste its values to Cells B1:B4 if cell B5=1 (or whatever). The Macro with copy and paste works (I recorded it and in my testing it was ok). And also the function, that contains If-Then status of cell B5, works and calls correctly the Macro.
Yet when the macro is called by the function (=CopyMyCells(B5)), the Macro (MacroCopy) runs - I tested this with a Msgbox - but stops just in doing what I need, i.e. in doing the copy-paste process. Here the code which is placed in a module of the proper Worksheet (Excel 2003, on WinXPSp3):
[Code] ........
View 6 Replies
View Related
Apr 18, 2009
I have a macro that asks the user what pages they would like to print on a particular sheet. In the example below, a button will be assigned to pages 1-5 on a sheet and thus the user has the option of printing from page 1 up to page 5. Any page number outside this range will result in an error message and the user will be asked to re-enter the end page number. This is the code I pulled from this forum and partially modified:
View 4 Replies
View Related
Oct 30, 2012
I have a spreadsheet that allows users to paste set data from a PDF Image (using OCR) straight into Excel and then use the MID function to split the data accordingly.
Unfortunately, the OCR isn’t too intuitive and gets it wrong sometimes.
So to counter this, in another sheet (in the same workbook) I have a manual input section, and a simple macro button that pastes this data into the same fields where the OCR text would be, so that the main sheet works exactly the same way as before.
The problem is, and most likely due to the simplicity of the sheet, if a combination of OCR pasting and manual inputting is used, when I hit the paste button, it over rides the OCR data with blank cells
In the link below I have shown what is currently happening (1, 2, 3), and an example of what I would actually like it to do (4, 5, 6).
Example - Online Spreadsheets - EditGrid
So, in the 2nd scenario, I would like “5” to recognise that the respective cells in “4” already contain data and fill them ‘Grey’. This I have already achieved with basic conditional formatting.
However, I need to take it 1 step further and say that if the parent sheets cell (Auto OCR) contains data, as well as filling cells (in sheet Manual) lock these cells off and prevent the end user from adding data and/ or being copied over to the parent sheet.
Is this possible?
The result then being the parent sheet with both OCR text and copied text from the manual input sheet.
Both sheets are protected anyway and only allow for user input in certain areas, so is it even possible to apply further protection once the sheet is locked already?
View 1 Replies
View Related
Aug 3, 2012
I have unprotected cells in excel where I need to change the content (number) and cell color, but I don't want the cell borders to change. I'm a beginner with vba. I've tried protect sheet and workbook options, but looks like I need a vba code and don't know where to start.
Win 7
Office 2007
View 4 Replies
View Related
Jan 26, 2007
I use a scanner that initiates a f2 command and trips my macro. I would like to use multiple scanners using a 8 port hub but I am having trouble with a scanner starting my macro and another scanner dumping data into my macro before the first one is finished. This is dropping scanned data into my macros. Is there a way to prevent the scan from accepting data until the macro has completed its cycle.
View 2 Replies
View Related
Mar 18, 2014
i have a challenge i need to prevent the value is more than A1 cell value in B1.
Example: if A1 value is 10 then unable to enter morethan 10 in B1 cell.
View 3 Replies
View Related
Jun 11, 2014
I am trying to write a VBA code that prevents the user from deleting row 8.
I do not want to use the sheet protection with password approach.
I simply want a code that prevents the user from deleting row 8 and notifies him via MSGBOX that such action is prohibited.
View 1 Replies
View Related
Feb 2, 2009
When user presses "ESC" key on an open userform, data he has changed in controls (simple textbox for example) gets resetted. Right? I'm seeing such behavior in Excel 2003. How about other versions?
I'd like to see some documentation about what exactly is going on, and how to prevent such unexpected feature (that forces data loss), but could not find.
I mean that i have no commandbutton with cancel=true. By default I want to keep the data user has entered/changed. Unfortunately this data reset finds place before any trappable event, or am i wrong?
I have not found any working way to capture keypresses on userform level. Userform has _KeyPress and other events, but those are not firing? If there is one, that would be helpful. Perhaps even on system level with some APIs? Altough that sounds way too complicated for a problem that should need only one little-known flag set. Perhaps there is such property somewhere?
View 6 Replies
View Related
Feb 11, 2008
I made up a small subprocedure that searches through a large list of zipcodes (These zipcodes are in a separate sheet). Whenever I execute my subprocedure in another sheet, it jumps to the zipcode sheet and then goes back to where I originally executed the subprocedure.
Is there any way that I can prevent the sheets from switching back and forth?
View 9 Replies
View Related
Jan 28, 2013
am trying to create a workbook template which collects data from users with user forms and some macros. Users assign a project name when workbook opens and then they are able to save as the workbook with name of project name. But i don't want them to save on my template mistakenly. How do i prevent this? I tried workbook_before close sub but i can manage that it recommends to save workbook with project name and if you don't want, it still asks you if you want to save workbook before close
View 7 Replies
View Related
Apr 4, 2014
I've got the following code which opens/gets the excel files from a specified directory and imports them into an open workbook. I've added a GoTo Error before my loop which checks if there are any files in the directory and shows an error message if it's the case. Problem is since the loop goes on till there are no more files in the directory, it goes back to the error. How to change that ?
View 3 Replies
View Related
Apr 26, 2014
I have 2 workbooks open. In the workbook that I am working in I run a macro from a userform to copy a worksheet from the other workbook that is idle in the back ground. I also display another user form that says "please wait" while the macro is running.
The problem I have is even though screen updating is set to false the screen switches over to the other workbook while it is copying the desired sheet and switches back to the workbook I am copying to after the macro completes. Also the "Please Wait" userform disappears while the other workbook is displayed and reappears when the initial workbook returns.
Below is my code which works without issue but perhaps there's a better way to copy between workbooks that would prevent the screen changes?
[Code] ........
View 3 Replies
View Related
May 16, 2014
Is there a code that can be input to prevent a document from being printed?
View 8 Replies
View Related
Jul 9, 2014
I use a few Functions in my VBA code. All these functions, are declared as "Public", and reside in a single module. However, they are called from many different modules during code execution. (i.e. many functions called from many modules - hence the "Public" declaration).
My issue is that in addition to being available to different VBA Modules, these Functions are also available on the worksheet as a UDF (so if a user presses "=" in the formula bar, the auto-complete shows these functions when the first characters match). Is there a way to remove the availability of the function on user worksheet? i.e. to allow a Function to be called from different modules in VBA, but prevent it from being available on the worksheet.
My current work-around is to prefix all Public Function names with letter "j" - as no excel formula seems to begin with it - none of them show up as auto-complete options. Nevertheless, the Functions are still available to the user - which is what I would like to prevent.
View 9 Replies
View Related
Sep 3, 2005
Is it possible to prevent a particular sheet from being deleted?
I have a workbook that contains sheets (of course). One of the sheets
serves as a "Help" sheet. I don't want users to accidentally (or intentionally)
delete just this sheet.
View 10 Replies
View Related
Oct 25, 2007
Is there anyway to turn off hyperlink. Everytime I put in an @ symbol in the cell and hit enter, it changes it to a hyperlink and changes the font and size. Is there anyway to turn this off or prevent this without having to click on the cell everytime and choose, remove hyperlink.
View 3 Replies
View Related