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
Bookmarks