So, I'm new to VBA and I have this code that adds a new row to two tables, one to a table on sheet3 which is visible and the other to a table on sheet5 which is hidden. My problem now is, with ScreenUpdating set to false at the beginning ad true at the end, when the code is run, the screen still flickers showing hidden sheets. How do I get this flickering to stop?
Sub Add_Observation()
'
Application.ScreenUpdating = False
Sheet3.Activate
ActiveSheet.Unprotect
Sheet5.Visible = True
Dim Ar As Integer, Br As Integer, A As Integer
'
Ar = Columns("B").Find(What:="S/N", After:=Range("B26")).Row 'Searching row of "S/N" header
Br = Range("B" & Ar).End(xlDown).Row 'Searching last row in EQUIPMENT table
A = (Br + 4)
B = (Br + 5)
Sheet5.Select
Dim Qr As Integer, Dr As Integer, D As Integer, D1 As Integer
'
Qr = Columns("B").Find(What:="S/N", After:=Range("B16")).Row
Dr = Range("B" & Qr).End(xlDown).Row
D = (Dr + 4)
D1 = (Dr + 2)
Sheet3.Select
Cells(Dr, "C").Select
If Range(Cells(Ar, 1), Cells(A, 1)).EntireRow.Hidden = False Then
Sheet3.Activate
Rows(A).Insert Shift:=xlDown 'Inserting new row
Cells(Br + 1, "B") = Cells(Br, "B") + 1 'Adding a sequential Number
Rows(Br).Copy 'Copying format of last row
Rows(Br + 1).PasteSpecial Paste:=xlPasteFormats 'Pasting format to new row
Application.CutCopyMode = False 'Deactivating copy mode
Sheet5.Select
If Range(Cells(Qr, 1), Cells(D, 1)).EntireRow.Hidden = False Then
Sheet5.Activate
Selection.Rows(D).Insert Shift:=xlDown 'Inserting new row
Rows(D1).Insert Shift:=xlDown
Cells(Dr + 1, "B") = Cells(Dr, "B") + 1 'Adding a sequential Number
Rows(Dr).Copy 'Copying format of last row
Rows(Dr + 1).PasteSpecial Paste:=xlPasteFormats 'Pasting format to new row
Application.CutCopyMode = False 'Deactivating copy mode
Application.ScreenUpdating = True
Else: GoTo G
End If
End If
G:
Sheet3.Activate
Range(Cells(Ar, 1), Cells(A, 1)).Select
Selection.EntireRow.Hidden = False
Sheet5.Activate
Range(Cells(Qr, 1), Cells(D, 1)).Select
Selection.EntireRow.Hidden = False
Sheet3.Select
Sheet5.Visible = False
Cells(Br, "C").Select
Sheet3.Activate
ActiveSheet.Protect
Application.ScreenUpdating = True
End Sub
Cells(x,y).SelectorSheet3.Activatemacro will show and perform the action. Which causes the flickers. So as said by @JohnyL AVOID those in all possible ways - nishit dey