Ambar
Ambar

Reputation: 35

How do I use VBA to keep the value of a cell in Excel with a limit and loop when needed?

I'm working with some data that involves longitudinal degrees in column A.

The problem is that when the value in A24 is, say, 358.2244 and the value in A25 is 2.4488 the value in B24 becomes negative.

The value being displayed is -355.7756, which is technically correct, but I want only positive values, so according to my requirement, 4.2244 should be displayed in that cell. What would the workaround for this using data validation or VBA be? I'm using Excel 2003 and Excel 2007.

Upvotes: 1

Views: 336

Answers (1)

GSerg
GSerg

Reputation: 78185

Instead =An - A(n-1) use =IF(An - A(n-1) < 0, 360 + (An - A(n-1)), An - A(n-1))

Upvotes: 4

Related Questions