Screenupdating=False not working

mssbass

Active Member
Joined
Nov 14, 2002
Messages
253
Platform
  1. Windows
I have the following code that copies a worksheet from a closed workbook to a worksheet in my open workbook. On the user worksheet (Main), I have a button the user clicks which updates all my vba. I don't want the code to show the user any worksheets it's working on but it seems to jump to the "NotifTasks" worksheet with this code below. Anyone know how to fix the "jumping" and keep it on the "Main" worksheet? Or is this even possible in Excel?

Sub Updatewb()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Sheets("Report 1").Delete
Const fromFile = "\\fol0ns01\xfer\MRO_Databases\JobTracker\NotifTasks.xlsx"
Dim srcBook As Workbook
Set srcBook = Application.Workbooks.Open(fromFile, _
UpdateLinks:=False, _
ReadOnly:=True, _
AddToMRU:=False)

srcBook.Sheets("Report 1").Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
Sheets("Report 1").Select
Cells.Select
Selection.Copy
Sheets("NotifTasks").Select
Cells.Select
ActiveSheet.Paste
srcBook.Close False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Possibly do away with the selects....

Code:
Sub Updatewb()
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    Sheets("Report 1").Delete
    Const fromFile = "\\fol0ns01\xfer\MRO_Databases\JobTracker\NotifTasks.xlsx"
    Dim srcBook As Workbook
    Set srcBook = Application.Workbooks.Open(fromFile, _
                                             UpdateLinks:=False, _
                                             ReadOnly:=True, _
                                             AddToMRU:=False)

    srcBook.Sheets("Report 1").Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
    Sheets("Report 1").Cells.Copy Sheets("NotifTasks").Cells(1, 1)
    srcBook.Close False
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Great! - Seemed to have worked!

What about this code?

Sub UpdatePaint()
Application.ScreenUpdating = False
Dim ws As Worksheet
Set ws = ActiveSheet
Application.Goto (ActiveWorkbook.Sheets("PAINT").Range("F5"))
LR = Cells(Rows.Count, 1).End(xlUp).Row
Range("f5").Resize(LR - 1) = "=IF(ISERR(SEARCH(""paint"",A5,1)),""N"",""Y"")"
Range("g5").Resize(LR - 1) = "=B5"
Range("h5").Resize(LR - 1) = "=c5"
Range("i5").Resize(LR - 1) = "=IF(D5=""(blank)"",NOW(),D5)"
Range("j5").Resize(LR - 1) = "=i5-h5"
Application.ScreenUpdating = True

End Sub
 
Upvote 0
I don't see that the screenupdating isn't working in your last code. All I can see is you telling it to change sheet which it does.
If you don't want it to change sheet then try...


Code:
Sub UpdatePaint()
    Dim LR As Long
    Application.ScreenUpdating = False
    Dim ws As Worksheet
    Set ws = ActiveSheet

    With ActiveWorkbook.Sheets("PAINT")
    
        LR = .Cells(Rows.Count, 1).End(xlUp).Row
        .Range("f5").Resize(LR - 1) = "=IF(ISERR(SEARCH(""paint"",A5,1)),""N"",""Y"")"
        .Range("g5").Resize(LR - 1) = "=B5"
        .Range("h5").Resize(LR - 1) = "=c5"
        .Range("i5").Resize(LR - 1) = "=IF(D5=""(blank)"",NOW(),D5)"
        .Range("j5").Resize(LR - 1) = "=i5-h5"
    End With
    Application.ScreenUpdating = True

End Sub

by the way why are the
Code:
Dim ws As Worksheet
    Set ws = ActiveSheet
lines in the code?
 
Upvote 0
With this code, I'm getting an application-defined or object-defined error on this line: " Range("e3").Resize(LR - 1) = "=A3""


Sub UpdateZMROSALESMap()
Dim LR As Long
Application.ScreenUpdating = False
With ActiveWorkbook.Sheets("ZMROSALES Map")
LR = Cells(Rows.Count, 1).End(xlUp).Row
Range("e3").Resize(LR - 1) = "=A3"
Range("f3").Resize(LR - 1) = "=""2/CT-HOLD/""&B3"
Range("g3").Resize(LR - 1) = "=c3"
Range("h3").Resize(LR - 1) = "=d3"
Range("i3").Resize(LR - 1) = "=IF(RC[-5]=TODAY(),""Y"",""N"")"
End With


End Sub
 
Upvote 0
You will get that error if you have nothing in column A of the ActiveSheet.
I say the ActiveSheet because you aren't qualifying your ranges (note the red periods/fullstops in the code below) and so your ranges are always referring to the ActiveSheet.

Code:
Sub UpdateZMROSALESMap()
    Dim LR As Long
    
    Application.ScreenUpdating = False
    
    With ActiveWorkbook.Sheets("ZMROSALES Map")
        LR = [COLOR="#FF0000"].[/COLOR]Cells(Rows.Count, 1).End(xlUp).Row
        [COLOR="#FF0000"][B].[/B][/COLOR]Range("e3").Resize(LR - 1) = "=A3"
        [COLOR="#FF0000"][B].[/B][/COLOR]Range("f3").Resize(LR - 1) = "=""2/CT-HOLD/""&B3"
       [COLOR="#FF0000"] [B].[/B][/COLOR]Range("g3").Resize(LR - 1) = "=c3"
      [COLOR="#FF0000"]  [B].[/B][/COLOR]Range("h3").Resize(LR - 1) = "=d3"
        [COLOR="#FF0000"][B].[/B][/COLOR]Range("i3").Resize(LR - 1) = "=IF(RC[-5]=TODAY(),""Y"",""N"")"
    End With
    
    Application.ScreenUpdating = True

End Sub
 
Upvote 0
I should have said
You will get that error if you have nothing in column A (or only cell A1 used in column A) of the ActiveSheet.

You will also get the same error even with the qualified ranges if only cell A1 is used in column A of Sheets("ZMROSALES Map").
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,565
Members
449,038
Latest member
Guest1337

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top