The code below is not in any way optimized or generalized. It is as close to your sample code as possible & designed to show you an answer based on your original code. I would suggest using comboboxes rather than textboxes, and/or using validation to make sure that the entries are all numeric. The code below doesn't go that far - it only answers your question based on the code you provided: