ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help to simplify code. (https://www.excelbanter.com/excel-programming/275851-help-simplify-code.html)

Michael Beckinsale

Help to simplify code.
 
Hi,

I have a spreadsheet where l need to call a macro when a particular cell is
changed. There are approx 100 cells (not adjacent) where l need to trigger
the macro. They are all on the same worksheet.

In the following example l have written If statements for 3 of the cells.

Obviously l do not want to write IF statements for all 100 instances.

Can somebody tell me what the code is to effectively list all the cells that
will trigger the IF statement and thus write only 1 IF statement ?

All suggestions warmly received.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Target.Address(False, False) = "B9" Then
Call AutoFitMergedCellRowHeight
End If

If Target.Address(False, False) = "F9" Then
Call AutoFitMergedCellRowHeight
End If

If Target.Address(False, False) = "B14" Then
Call AutoFitMergedCellRowHeight
End If

End Sub





All times are GMT +1. The time now is 03:05 PM.

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