I want to be able to create formulas where the output can act as the input. For example, I tried to write a simple proof of concept script where you can convert between pounds and kilograms. So if you type in a value for pounds, it'll update the kilograms cell. And if you type in a value for kilograms - it'll update the pounds cell.
This is what I came up with:
Problem is that it doesn't fully work. It works perfectly as long as you don't enter in a value for pounds, then try to enter in the same value for kilograms. I can't figure out why though!![]()
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Static PreviousCell As Range If Not (PreviousCell Is Nothing) Then If PreviousCell = Range("H4") Then Range("I4").Value = Range("H4").Value * 2.20462262 ElseIf PreviousCell = Range("I4") Then Range("H4").Value = Range("I4").Value / 2.20462262 End If End If Set PreviousCell = Target End Sub
Also - I'm very new to writing code for Excel (more of a C programmer myself...) - so if there are better ways of doing any of this I'd be all ears!
Thanks!
Bookmarks