Running Simple VBA Code Causing Screen Errors

Nov 30, 2009

I have a rather large workbook (30 sheets, 10MB) that has one worksheet with many INDIRECT functions in it (pulling data from the same file, different tabs). I am working to put simple code into the workbook to protect and/or unprotect all worksheets. I have gotten code to work to both protect and unprotect all the sheets, but when I run the unprotect code (see below), and then I go to edit the workbook, data from the sheet with many "indirect" functions temporarily "overwrites" the data on the active sheet (this is fixed when I scroll my mouse over the effected cells). I am developing this workbook for other users, so I'd like to fix this before sending it off to them.

This problem does not happen until after I run the following .....

View 14 Replies


ADVERTISEMENT

Very Simple Macro Not Running Consistently?

Jul 30, 2012

I have two short macros, shown below. The first changes the font color of the cells in named range BackgroundFont1 to the background color of the cells. The second macro turns the font color in these cells back to black.

I call these subs in other macros. The first one works all the time. The second one works only occasionally - more often than not it just hangs up Excel entirely and shuts down the program. It happens even if I just run the BlackFont macro on its own.

The error message I get at times is "Method color of Object Font failed".

Macro 1

Code:
Sub BackgroundFont1()
For Each cell In Range("BackgroundFont1")
cell.Font.Color = cell.Interior.Color
Next cell
End Sub

Macro 2

Code:
Sub BlackFont()
For Each cell In Range("BackgroundFont1")
cell.Font.Color = vbBlack
Next cell
End Sub

These are the cells in the ranged named BackgroundFont1.

Code:
=Demo!$JY$581:$KI$590,Demo!$JY$599:$KI$602,
Demo!$JY$612:$KI$615,Demo!$JY$624:$KI$625,
Demo!$JY$643:$KI$644,Demo!$JY$656:$KI$658,
Demo!$JY$667:$KI$669,Demo!$JY$677:$KI$679,

[Code] ......

View 6 Replies View Related

Running Simple Macro On Multiple Sheets

Oct 22, 2013

I need to run a very simple macro (filter by date, copy, and paste) on every worksheet in a workbook, and then place that data into a summary page at the "end" of the workbook. Most other posts had to do with some kind of formatting that would work in succession on the sheets linearly from left to right (for lack of a better way to put it). My problem, however, is that the data would need to be pasted into the summary worksheet, and then somehow the macro would come back to the next sheet (after the one it just did) and do it all over again, so on and so forth. The worksheets are arranged alphabetically, but other than that there is no sort of easily identifiable progression between them (i.e. Sheet1, Sheet 2, etc.).

View 9 Replies View Related

Screen Flickering While Filter Is Running

Apr 17, 2009

In the example included, a filter is running. (Status; Watching, Column G) Whenever you type something in the sheet, the screen is flickering. When the filter isn't running, nothing unusual happens. How can I fix this? Marco

View 2 Replies View Related

Screen Flashing When Running VBA Macro

Jan 4, 2010

I have a VBA macro that sort several worksheets during th e processing but the screen flashes it move between worksheets. I would like to be able to just show a messae or have the display stay on the strting worksheet

View 9 Replies View Related

Stop Screen From Jumping While Running Macro

Apr 25, 2007

I've created a macro that runs for about 3 seconds. While the macro runs, the active worksheet display jumps around because of the various cell references being addressed in the macro.

Is there a way to stop the jumping around? How can a simple "Progress" screen be displayed while the macro is running?

View 4 Replies View Related

VBA Code Causing Intermittent Crashes

Aug 12, 2008

I have a set of userforms, two of which are big with 4 pages and many buttons, labels and textboxes that run or are involved in code being run from user input to the userform.

For some reason certain codes are cauing excel to fully crash, executing these codes will make excel crash each time and the only way to prevent it (that I have found) is to open the userform in VB editor and then close VB editor again, the code will then work perfectly for a while and then it will start crashing again (it is normally a few saves and open/closes later that this occurs).

Logically thinking, opening the userform in VB must reset something that gets corrupted or set incorrectly....

View 7 Replies View Related

Code In BeforeSave Event Causing A Double Save

Jul 22, 2009

In the situation where I shut down my model (i.e. not just press Ctrl+S, but shut it down), the following code saves the model twice. I only want it to save once. I really can't see why it saves a second time.

NB: I know if you set Cancel to True in the BeforeSave event, it should prevent the model from saving after the event, but even when set to true in the below code, it still saves...

Private Sub Workbook_BeforeClose(Cancel As Boolean)
bIsClosing = True 'Given we shut model, this public bIsClosing is set to true...
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim wsArray() As Variant
Dim iCnt As Integer
Dim wsSht As Worksheet
Application. ScreenUpdating = 0
Splash.Visible = True 'Splash is codename for warning spreadsheet, this is left
'visible while all other sheets are to be hidden.......................

View 9 Replies View Related

Type Conversion Errors In VBA Code

Sep 5, 2007

I have an existing code that runs almost flawlessly but I am running in to formatting cells error (or at least I think that is the problem).

For example, here is a line of code where my error lies:

If Worksheets(FirstSheet).Cells(Counter, ColtoMove) = MoveIf Then
'DO SOME ACTION

If I put my cursor on MoveIf it shows the expect number of 4500016239…….BUT it errors!

When I step through the code and go to the worksheet (or go to the left side of the = in the above code the data in the cell is “4.5E+09“.

I’ve attempted to change the formatting of this cell range to “Text” by the following With statement:

With Worksheets("CreateOrderFormsData")
.Range("AC:AC").NumberFormat = "Text"
End With

Note: if I verify the cells formatting after the above code is ran by rt click on the cell, format cells the Number field is set to “CUSTOM” and the Type: field is set to “TEXT”. Is this the problem? Please read on.

But that did not seem to do the trick…..actually if I now go to the left of the = again (which is now set to text) the data is “###########” in the cell, in the formula bar the number is the expected 4500016239 though but the CODE STILL FAILS!

Am I on the right track…..can anyone assist with this error please?

View 9 Replies View Related

FileSearch Code Errors In 2007

Jan 26, 2008

Sub CombineWBs()
Dim wb As Workbook
Dim newWB As Workbook
Dim i As Long

On Error Resume Next

With Application.FileSearch
.NewSearch
.LookIn = "C:Budget"
.Execute
Set wb = Workbooks.Open(.FoundFiles(1))
RenameWS wb
wb.Worksheets.Copy
Set newWB = ActiveWorkbook
wb.Close SaveChanges:=False
For i = 2 To .FoundFiles.Count
Set wb = Workbooks.Open(.FoundFiles(i))
RenameWS wb
wb.Worksheets.Copy After:=newWB.Worksheets(newWB.Worksheets.Count)

View 9 Replies View Related

Simple Code In 'Private Sub'

Jan 8, 2008

I usually create fairly simple macros using 'button' feature. However, now I'm using the 'CommandButton', as I had to make buttons highlighted once selected - So I have a choice of five options, whichever the user chooses that option background changes, the others stay grey...anyway, thats the fancy-editing done, but now when i enter a simple instruction - hide rows function - I get the error message "Select method of range class failed"

Here is the full code - like i say it works fine when its just the editing, but when i try to actually hide rows it doesn't work. - I will also add that the code is inside 'Microsoft Excel Objects' and further 'Sheet 1 (INDEX)' - not a module - I'm not sure if this is important.

Private Sub JackStart_click()

JackStart.BackColor = 32896
JackStart.ForeColor = 16777215
JackStart.Font.Bold = True
Majix.BackColor = 8421504
Majix.ForeColor = 0
Majix.Font.Bold = False

Sheets("Bank Reconciliation").Select
Rows("3:3").Select
Selection.EntireRow.Hidden = True

Sheets("INDEX").Select
Range("A1").Select

End Sub

View 9 Replies View Related

Code For Button Errors Due To Worksheet Name Change

Oct 15, 2008

My code works well if the worksheet name is Sheet1. It will change constantly. I have alot of other similar workbooks that are not affected and cannot figure this out. Here is the code that I get the error at: ....

View 9 Replies View Related

Before Close Code Errors When Closing From Other Workbooks

Nov 21, 2006

I have a workbook which includes a simple set of options on closing such as selecting the front sheet, restoring scrollbars and saving the workbook. To avoid problems with subscripts out of range I am using the ThisWorkbook statement to close the workbook.

This works fine and causes the workbook to close when close is clicked on any excel window. The problem is that excel falls over when it tries to resume closing the other workbooks. I am given (ironically) an error saying "excel has encountered a problem and needs to close". Does anyone know how to work around this?

My code is below:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Call Toolbars9(True)
With ActiveWindow
.DisplayHorizontalScrollBar = True
.DisplayWorkbookTabs = True
End With

View 8 Replies View Related

Identify Formula Errors Macro Code

Mar 6, 2008

i would like an if macro to pick up if cell dest (i have used a case to define this cell) contains an error or more imoprtantly #REF! then change the offending cells to 0 and put up a message box to put "Check XTA". i have found some that i think may work but i didnt understand them (they had function in them :smask so i couldnt put them in.is there a way to put them in with out functions or could someone point me in the right direction.

View 4 Replies View Related

Suppress Macro Code Run-Time Errors

May 9, 2008

how to supress the continue,end,debug, message when there is a vba error. The idea being that if there is a bug in my system that I have no realised, I don't want my end user seeing that message! I would preferrable design my own error message to appear instead.

View 2 Replies View Related

FOR, IF, NEXT... Error In VBA While Attempting A Simple Code

Jan 9, 2009

Had a bit of code I was working on for a guy on here, and came across a problem while putting the finishing touches on it. It's since been solved by someone else, but for future reference...

View 13 Replies View Related

Code Errors On Setting Cell Values To A Formula?

Jul 15, 2014

the following two statements return the error "Application-defined or object-defined error"

Code:
Sheets("Purchase").Range("PurchaseTax").FormulaR1C1 = "=IF(RC[-1]0,ROUND(RC[-1]/11,2),"")"
Sheets("Purchase").Range("FreightTax").Formula = "=IF(FreightCharge0,ROUND(FreightCharge/11,2),"")"

View 2 Replies View Related

Sheet Event Code Errors If Target Deleted

Mar 25, 2008

I have added this bit of code to change the apperance of entered time from 0835 to 08:35

UserInput = Target.Value
If UserInput > 1 Then
NewInput = Left(UserInput, Len(UserInput) - 2) & ":" & Right(UserInput, 2)
Application.EnableEvents = False
Target = NewInput
Application.EnableEvents = True
End If

And it works like a charm. Except that if the content in one of the cells later is deleted a "Run time error 13" is the result. Debug leeds to the line "If Userinput >1 Then"

Can this error be avoided..?

View 3 Replies View Related

Event Code Errors When More Than One Cell Changed/Deleted

Apr 15, 2008

I used the code below for Conditional Formatting. This works fine but the VBA-code crashes when I delete more than one selected cell. Is there a simple modification possible to prevent this from happening?

Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer
If Not Intersect(Target, Range("A1:C250")) Is Nothing Then
Select Case Target
Case 1
icolor = 6
Case 2
icolor = 12
Case 3
icolor = 7
Case 4
icolor = 53
Case 5
icolor = 15
Case 6
icolor = 42
Case Else
'Whatever
End Select

Target.Interior.ColorIndex = icolor
End If
End Sub

View 3 Replies View Related

Code For Simple Checkbox On User Form.

Jan 21, 2010

I really don't know how to code a checkbox correctly. On the sheet, I have a form with CheckBox1 and Checkbox2. I would like Checkbox2 disabled until Checkbox1 is checked. Also, when Checkbox1 is checked, display Image1, otherwise Image1 is hidden. When CheckBox2 is enabled and checked, display Image2, otherwise Image2 is hidden. I know this is real beginner stuff, I'm still a rookie.

View 4 Replies View Related

Workbook Code Errors When Orginal Sheet Hidden Or Deleted

Oct 14, 2007

I copied the sheet and redid the format. I renamed the original dashboard sheet from count to "keep" and named the copy after the original "count" Everything still works great - until i either hide or delete the original count which is now named "keep". I get an error at the red colored line below ".publish false".

I have attached an image of the error....

View 7 Replies View Related

Calculations To Manual Before My Code Runs And Set It Back To Auto When My Code Is Done Running

May 12, 2009

I am dealing with several very large spreadsheets using VBA to do various things. I found that my code worked well, but was taking a long time to run. The biggest time consumer was my use of the AutoFilter features. I have since turned calculations to manual before my code runs and set it back to auto when my code is done running. What are the potential consequences of my turning calculations to manual and then back to auto?

View 2 Replies View Related

Simple Color Code Not Working On Specific Sheet

Jul 22, 2013

This very simple color code below worked before but now it gives "Application-defined or object-defined error". When I try it on a new workbook, it works fine.

Code:
Sub sdsdfsd()
Selection.Interior.Color = 65535
End Sub

View 1 Replies View Related

Code Affects Screen Display!

Mar 2, 2009

I use the following piece of code to Hide/Unhide columns as required by a specific worksheet.

View 4 Replies View Related

Code To Position Sheet On Screen

May 29, 2012

I'm using a bit of code (below) which is not amazing but which does seem to work, the idea being that entering a number then the active cell relating to that number will be highlighted and the sheeet position will "goto" it to move it into view on the screen. I have adapted this from something in one of my old Workbooks, and I admit it's probably a bit messy!

The problem is, it doesn't seem to always put the returned active cell in the same place, sometimes it's nicely central to the screen, but at others it's right at the top. As the numbers corrrespond to the top line of each little area of 30 rows, I'd like it to to come about 10-12 rows down. I can't seem to get this to work!

Code:
Sub FindSection()
Dim nm As Integer, txtnum As String, Found As Range
txtnum = Application.InputBox(prompt:="Enter a Number")
Set myRange = Worksheets("T&M SHEET").Range("K:K")

[Code]....

View 5 Replies View Related

VBA Code For Full Screen With Save As

Aug 21, 2013

i have an excel workbook containing approx 20 worksheets. What I would like to do is make the workbook go full screen when the user opens the file and allow the user to save as into the same file path the workbook is stored when closed

View 2 Replies View Related

An Object Code= Flickers The Screen

Nov 27, 2009

way i could stop my sheet from flickering everytime i change my cell selection via keyboard/mouse. i checked and this problem is only with code below that i run in view code of my sheet...

PHP
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Set ws = ActiveSheet
On Error GoTo errHandler

If Target.Count > 1 Then GoTo exitHandler
If Target.Address(False, False) = "Z3" Then
    Call GoToMatch
    Exit Sub
End If

View 9 Replies View Related

This Simple 10 Line Code Doesn't Work If Just The Reference Is Changed..

Jun 10, 2009

I asked for a macro to delete the whole row if a duplicate customer number was found in column B. Sometimes, though, my column numbers change. So, logically thinking, I simply changed the criteria, but the macro ONLY seems to work if duplicate customer numbers are in column B only.

This code below won't work if the Customer Number is in column D instead of B even if the reference of B:B is changed to D:D, it doesn't carry the macro over.?

View 3 Replies View Related

Delete Splash Screen UserForm & Code

Sep 4, 2006

Some time ago (not sure how long ago) I created a splash screen that comes up when I first load a particular workbook. There was only one worksheet in the workbook and at that time the data in the worksheet was not so relevant and hardly ever used. That workbook name is "Employees" and the worksheet name is "EmpData".
Subsequently, the worksheet ("EmpData") in the workbook "Employees" has became relevant to a new workbook named "Payroll" I created. This workbook is used all the time. It had four different active worksheets.

I realized last week that the data in "EmpData" was very relevant to the work in the "Payroll" workbook so I copied "EmpData" worksheet in it's entirety to the "Payroll" workbook as a fifth worksheet using the same name as before, "EmpData". Now each time I open the "payroll" workbook the splash screen shows up and hangs around for several seconds or longer. It has become quite irritating and I want to delete it.

View 3 Replies View Related

Mouse Click Freezes Screen - Code Still Executes

Jun 16, 2006

it would be possible to have text disappear after being displayed in Excel for a while.

My son and I played around with games (helping create a photographic memory, I told the youngster!) on the thing and until yesterday neither of us noticed that clicking the mouse anywhere (actually just clicking it) causes the screen to "freeze" while the code still happily erases the text in the background.

Hitting ESC allows the screen to cath up to the actual code EVEN THOUGH the ESC key is actually disabled from breaking the code.

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved