views:

486

answers:

1

Is there a way to improve performance in any meaningful way for the following VBA code in Excel?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   If Not Intersect(Me.Range("Group1"), Target) Is Nothing Then

     With wksData
       .Range("Group1Column").Value = Target.Column
       .Range("Group1Row").Value = Target.Row
     End With
   End If

End Sub

I've added conditional formatting that looks at the Group1Column and Group1Row named ranges. I can't tell if my performance issue is related to the overkill of SelectionChange or the conditional formatting, but there's a noticeable lag that'd I'd like to get rid of.

The conditional formatting is super basic (something like Column($D3) = Group1Column), and it's only for 'eye-candy' purposes, but it would be helpful for the solution overall.

Some things I've tried: .ScreenUpdating, .EnableEvents, .Calculations. .ScreenUpdating does ensure the user has to wait before selecting their next cell, but not quite what I had in mind.

Any tips would helpful!

+1  A: 

It's lightening fast for me. Do you have a lot of other calculations going on in the workbook? What version are you using?

Dick Kusleika
Huh. Well, I'll have to do a double-take on this then, as it's definitely not lightning quick for me. <p>As far as stats, the workbook has only 29 formulas, and they're non-volatile (just index functions). I'm on XL 2007, and my system is at 2gigs of RAM, plain ol' intel processor in the 3ghz range... I am admittedly a bit perplexed. I'll test and get back.
TimS
Thanks for the confirmation. Ironically, I stripped the above code down so that it would make sense for my posting, and when I re-tested it (starting from my posted code) it was working as you described it. I added complexity back to the code as I went, removed some redundancy, tested at each new addition, and now it seems to be working perfectly. Oh and, ".EnableEvents = False" by itself (no .ScreenUpdating or .Calculation changes) helped trim some microseconds off too. Thanks again!
TimS
There's nothing worse than tearing something down, building it back up, and not being able to reproduce the problem, :) But I'm glad you got it working.
Dick Kusleika