Maintain Focus on current Worksheet?

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,341
Office Version
  1. 365
Platform
  1. Windows
I have a userform with a command button that copies a range of formulas and then performs a pastespecial in a worksheet. My problem is, the Userform with the command button is launched from a differnt sheet then where the Copy/Paste takes place. 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


HELP!!!! ANY HELP IS VERY APPRECIATED.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
As we progress in writing code we do not use Activate/Select unless we actually need to see something on screen. In this case you can replace your copy/pastespecial code (and eliminate the need to activate the sheet) with :--
Code:
    ' code
    Worksheets("HOURS").Range("AE3:AE761").Copy
    Worksheets("HOURS").Range("AD3").PasteSpecial _
        Paste:=xlPasteFormulas, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
 
Upvote 0

Forum statistics

Threads
1,214,804
Messages
6,121,652
Members
449,045
Latest member
Marcus05

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