Tuesday, June 10, 2008

Tips for Excel VBA

In a small Excel document, the input data need to be validated before saving. That is why a VBA code is needed. I hope this can also be done using formula, but a short VBA code look more sophisticated.

Firstly, Target is a range variable where the just input data located, it is a cell, generally. Secondly, I need to autofill or change some cells according to the new input data, I have to call the subroutine from the Change event, but, of cause, we can not modify the cell directly, otherwise, it will call such subroutine continously into a endless loop. What we need is inserting the code between
Application.EnableEvents = False
....
Application.EnableEvents = True

Finnally, to check if a cell is empty or not can be done by built-in function IsEmpty().

No comments: