Help! I can see the code running

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,332
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
--------------------------------------------------------------------------------
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Don't forget to turn the screen updating back on at the end of your code.

Code:
Application.ScreenUpdating = True
 
Upvote 0
Put
Code:
application.screenupdating = false
as the first line of the macro and put
Code:
application.screenupdating = true
right before End Sub
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,215
Members
448,554
Latest member
Gleisner2

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