ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Worksheet_Change with discontinuous cells (https://www.excelbanter.com/excel-programming/334424-worksheet_change-discontinuous-cells.html)

jkg

Worksheet_Change with discontinuous cells
 
Hi,

I'm working on a commission calculation form. At present, all calculation
rows are hidden until they click "Calculate Commission" (presumably after
they enter all the information...). That unhides the appropriate rows and
shows the calculations. But if they change certain cells, the macro needs to
be run again (as the rows that are shown depend on the choices, and if they
change those choices, different rows may need to be shown/hidden).

There's probably a simpler way to do this, but what I'm thinking of now is
writing code under the worksheet_change event with the target being the
particular cells that would prompt a need for recalculation. Only those cells
aren't continguous. For example, they are
A11
A12
A13
B6
B19
E19
G19

Is there a way to make the target these multiple ranges?

Or if you have a suggestion of a better way, in general, to handle this,
please fire away! My programming experience is mostly in Access, so I'm
struggling with some of the Excel stuff.

Thanks!

Bob Phillips[_7_]

Worksheet_Change with discontinuous cells
 
Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range("A11:A13,B6,B19,E19,G19")) Is Nothing
Then
With Target
'do your stuff
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This i

--
HTH

Bob Phillips

"JKG" wrote in message
...
Hi,

I'm working on a commission calculation form. At present, all calculation
rows are hidden until they click "Calculate Commission" (presumably after
they enter all the information...). That unhides the appropriate rows and
shows the calculations. But if they change certain cells, the macro needs

to
be run again (as the rows that are shown depend on the choices, and if

they
change those choices, different rows may need to be shown/hidden).

There's probably a simpler way to do this, but what I'm thinking of now is
writing code under the worksheet_change event with the target being the
particular cells that would prompt a need for recalculation. Only those

cells
aren't continguous. For example, they are
A11
A12
A13
B6
B19
E19
G19

Is there a way to make the target these multiple ranges?

Or if you have a suggestion of a better way, in general, to handle this,
please fire away! My programming experience is mostly in Access, so I'm
struggling with some of the Excel stuff.

Thanks!





All times are GMT +1. The time now is 02:12 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com