+ Reply to Thread
Results 1 to 6 of 6

Screen Updating Help

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-13-2012
    Location
    Midwest
    MS-Off Ver
    Excel 365
    Posts
    124

    Screen Updating Help

    I know that when I use 'select' or 'activate' the screenupdating is set true. But I dont know how to change my code to fix this. At the very least, I'd like to not see the changes in the "Data" sheet. I know my code isnt the most efficient, but it works. Thank you!
    Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    Call unprotect
    Dim r As Long
    Dim c As Range
    Dim rng As Range
    Dim i As Integer
    Dim cell As Range
    Dim tm As Date
    Dim rw As Long
    Dim rw1 As Long
    Dim selrange As Range
    Dim ws As Worksheet
    Dim shift As String
    Dim facility As String
    Dim prod As String
    Dim trans As String
    Dim trans1 As String
    
        Set selrange = Selection
        Set ws = ActiveSheet
        shift = ws.Range("f1").Value
        facility = ws.Range("g1").Value
        prod = ws.Range("h2").Value
        
        Selection.MergeCells = False
        For Each c In Selection
            c.Value = c.Offset(0, 1).Value
            c.NumberFormat = ";hh:mm"
            c.HorizontalAlignment = xlCenter
            c.VerticalAlignment = xlCenter
            c.Interior.Color = RGB(191, 191, 191)
            c.Font.Color = RGB(191, 191, 191)
        Next c
        
        tm = Selection.Cells(1, 1).Offset(0, -2)
        Sheets("Data").Activate
            Set rng = Range(Range("e2"), Range("e" & Rows.Count).End(xlUp))
            For Each cell In rng
                i = 0
                If cell.Value = tm Then
                    rw = cell.row
                    Range("a" & rw & ":aj" & rw).Select                  <-----------------------------
                    Selection.Copy
                    Range("ak" & rw).Select                              <-----------------------------
                    ActiveSheet.Paste
                    Range("a" & rw).Value = Date 'year
                    Range("b" & rw).Value = Date 'month
                    Range("c" & rw).Value = Date 'day
                    Range("d" & rw).Value = shift
                    Range("e" & rw).Value = Now
                    Range("f" & rw).Value = facility
                    Range("g" & rw).Value = "CLEARED"
                    Range("h" & rw & ":aj" & rw).ClearContents
                Else
                i = i + 1
                End If
            Next cell
            rng.Select                                                  <------------------------------
            rw2 = Selection.Rows.Count
            If i = rw2 Then 'IF THERE ARE NO MATCHING ENTRIES IN THE MASTER FILE
                MsgBox ("There is no matching entry in the Master file. Please inform the administor.")
                Call protect
                Exit Sub
            End If
        ''RED LINE
            Columns("ak:ak").Activate                     <-----------------------------
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .Color = -16776961
            .TintAndShade = 0
            .Weight = xlThick
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
        Cells(1, 1).Select
        
    ws.Select
    Range("d1").Select
    Unload Me
    Call protect
    Application.ScreenUpdating = True
    End Sub
    - Luke

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Screen Updating Help

    You could try setting your worksheet to be an object, do
    Dim wsData as Excel.Worksheet
    you don't need to activate your sheet, so for example

    set wsData = ThisWorkbook.Worksheets("Data")
    
    set rng =wsData.Range(Range("e2"), Range("e" & Rows.Count).End(xlUp))
    wsData.Range("a" & rw & ":aj" & rw).Select                  
    wsData.Selection.Copy
    wsData.Range("ak" & rw).Select                              
    wsData.Paste
    I haven't tested that
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Forum Contributor
    Join Date
    09-13-2012
    Location
    Midwest
    MS-Off Ver
    Excel 365
    Posts
    124

    Re: Screen Updating Help

    Compile Error: Method or Data not found for wsData.Selection.Copy
    Thank for trying.

  4. #4
    Forum Contributor
    Join Date
    09-13-2012
    Location
    Midwest
    MS-Off Ver
    Excel 365
    Posts
    124

    Re: Screen Updating Help

    Compile Error: Method or Data not found for wsData.Selection.Copy
    Thank for trying.

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Screen Updating Help

    selecting or activating does not turn screenupdating on

    perhaps
    set wsData = ThisWorkbook.Worksheets("Data")
    
    set rng =wsData.Range(Range("e2"), Range("e" & Rows.Count).End(xlUp))
    wsData.Range("a" & rw & ":aj" & rw).Copy destination:=wsData.Range("ak" & rw)
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  6. #6
    Forum Contributor
    Join Date
    09-13-2012
    Location
    Midwest
    MS-Off Ver
    Excel 365
    Posts
    124

    Re: Screen Updating Help

    Thank you. That does work. I decided to delete the other bit of code regarding the red line, not worth the hassle. Now it doesn't flash to Data sheet. Enjoy the weekend!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1