View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Gary Keramidas Gary Keramidas is offline
external usenet poster
 
Posts: 2,494
Default Position independent code

give those cells a range name and use that instead of the address

--


Gary


wrote in message
ups.com...
Greetings.

I wrote a few event handlers that do calculations when some cells are
modified.
For example:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$6" Then
Application.EnableEvents = False
Range("B6").Value = Range("C6").Value / Range("B13").Value
Application.EnableEvents = True
Else
Application.EnableEvents = False
Range("C6").Value = Range("B6").Value * Range("B13").Value
Application.EnableEvents = True
End If
End Sub

But then I insert rows to my sheets add/remove/reposition some stuff
and all my VBA functions fail since Cell Addresses are hard-coded.

How can I reference cells by name, or some sort of a dynamic reference
(like Excel formulas that get automagically updated when you move
things around)?

Thanks