Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Worksheet Selection Change - however slowing down spreadsheet

Posted on 2010-11-19
6
Medium Priority
?
548 Views
Last Modified: 2013-11-25
I currently have a excel form which users input date
1.  Users have to fill in mamdatory data in first sheet.
2.  At the abocve sheet users choose "systems", and this will open unhide extra sheets to be filled in.
3.  When choosing system (more than 1) some combinations are immendiatelty defaulted if 2 systems go together,
2&3 use Worksheet Selection Change  macro,  This runs the macro everytime you move cells anywhere in the sheet.    This is slowing down the sopreadsheet, and using a curser to move down can be very slow.

1.  is there a way of slectio change cabn apply to only cells moved within a region.
2.  What else do uyou recommend?

Start of my code eg


If Range("J20").Value = "Summit XXX" Then
Sheets("Summit 3.83").Visible = False
Sheets("Summit 3.75").Visible = True
Sheets("Murex").Visible = False
Sheets("Martini").Visible = False
Sheets("TOMS").Visible = True
'Sheets("Paris (Hierarchy)").Visible = True
Range("F20").Value = "X"
Range("F34").Value = "X"
Range("J34").Value = "Yes"

ElseIf Range("J20").Value = "Summit XXY" Then
Sheets("Summit 3.83").Visible = False
Sheets("Summit 3.75").Visible = True
Sheets("Murex").Visible = False
Sheets("Martini").Visible = False

etc....... many lines.


Thanks
0
Comment
Question by:yasanthax
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 24

Assisted Solution

by:Tracy
Tracy earned 400 total points
ID: 34174917
Add this to the beginning of your code:
Application.ScreenUpdating = False
Application.EnableEvents = False

Then add this to the end of your code:
Application.ScreenUpdating = True
Application.EnableEvents = True
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34174973
1.  is there a way of slectio change cabn apply to only cells moved within a region.
2.  What else do uyou recommend?

Can I see your workbook?
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34174975
To address the other part of the question do
If Not Intersect(Target, Range("A1:D7")) Is Nothing Then
...
End If

Open in new window


To only run if the selected cell is in Range("A1:D7")
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34174985
So something like this
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("A1:D7")) Is Nothing Then
  Application.ScreenUpdating = False
  Application.EnableEvents = False
  'All the code goes here
  Application.ScreenUpdating = True
  Application.EnableEvents = True
End If
End Sub

Open in new window

0
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 1600 total points
ID: 34175025
Any time you turn off Events, ScreenUpdating etc, you should consider handling errors so that if the code crashes, the stuff doesn't stay off (if it gets an error, it will stop executing before it gets to where it turns it all back on) So I do this
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("A1:D7")) Is Nothing Then
  Application.ScreenUpdating = False 'Make it so the screen doesn't change while the code runs
  Application.EnableEvents = False 'Make it so other events don't fire
  On Error GoTo crash 'If it has an error move to the crash label so stuff gets turned back on
  'All the code goes here
  
crash:
  If Err.Number <> 0 Then 'If an error happened
    MsgBox "Error: " & Err.Description
  End If
  On Error GoTo 0 'Fix error handling
  Application.ScreenUpdating = True 'Turn it all back on
  Application.EnableEvents = True
End If
End Sub

Open in new window


But if using intersect speeds it up enough, you don't need to bother with all that.Good info though.
0
 

Author Closing Comment

by:yasanthax
ID: 34186708
Exactly answered question as stated and in addition added error handling
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question