Help! I can see the code running

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
1,784
Office Version
  1. 365
Platform
  1. Windows
I have a userform (UserForm45) with a TextBox that copies a range of formulas and then performs a pastespecial in a worksheet. My problem is, the Userform with the TextBox (TextBox42) is launched from a differnt sheet then where the Copy/Paste takes place (Sheet (1)). UserForm45 can be activated from various sheets, so I am using the Set ws = ActiveSheet function to get me back to where I started. The problem is that you can see the sheets change while it performs the code and it looks very unprofessional. How do I keep the original worksheet in view while the code is performed?

Here is the code:
----------------------------------------------------------------------------------
Private Sub TextBox42_Change()
'Identifies the current sheet as ws
Set ws = ActiveSheet

'Code
Sheets("HOURS").Activate
Range("AE3:AE761").Select
Selection.Copy
Range("AD3").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False

'Returns to current page after code (the current page could be different depending on where the Userform was launched from
ws.Activate
End Sub
--------------------------------------------------------------------------------
 

Some videos you may like

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Barrie Davidson

MrExcel MVP
Joined
Feb 10, 2002
Messages
2,330
Don't forget to turn the screen updating back on at the end of your code.

Code:
Application.ScreenUpdating = True
 

wwbwb

Well-known Member
Joined
Oct 20, 2003
Messages
513
Put
Code:
application.screenupdating = false
as the first line of the macro and put
Code:
application.screenupdating = true
right before End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,119,127
Messages
5,576,237
Members
412,709
Latest member
AD04
Top