AndyTampa
Board Regular
- Joined
- Aug 14, 2011
- Messages
- 199
- Office Version
- 365
- 2016
- Platform
- Windows
I'm trying to create a tool we can use that automatically validates the data entered on it. I'm having difficulty putting my formula into a VBA alternative.
On the main sheet are the two columns I'm concerned with at the moment. There is an Amount column and a Code column. I have a separate worksheet where a table contains the codes for credits and charges. As my macro runs down the main sheet line-by-line, validating the data, I need it to check these two cells on each line and perform actions based on the tests. Here is the formula from which I'm trying to build code.
The formula works as a test, but instead of putting Invalid or Valid in a cell, I want to highlight cells that are invalid and increase counters I have set up. As important, if not more so, is the order the tests are done. I'm confusing myself with all the If/Thens running through my head. The monetary tests are moot if the codes don't exist on the other sheet.
Should I be testing for correctness first in an IF statement of some kind so the tests only get done in the ELSE statement? For example: IF (the code is a charge AND the amount is over 0) OR (the code is a credit AND the amount is under 0), don't test anything else. ELSE run through the tests. Those are the only two ways this data is valid. How would I write that?
The tests I need to do if the pair are invalid are:
1) If the Amount cell is blank or 0.00, increase the invalid data count by one and highlight the amount cell.
2) If the Code cell is blank or doesn't exist in the Codes table on the AdjCodes sheet, increase the invalid data count by one and highlight the Code cell.
If those conditions exist, there is no point in checking for the "polarity" of the adjustment. Testing the Amount cells should be skipped to avoid marking one bad cell in two different counters (I think ).
3) If the code is in the Charge column of the Codes table, but the amount is less than 0.00, increase the Adjustment Mismatch count by one and highlight both cells
4) If the code is in the Credit column of the Codes table, but the amount is more than 0.00, increase the Adjustment Mismatch count by one and highlight both cells
I'm missing something. There appear to be overlaps in my tests.
On the main sheet are the two columns I'm concerned with at the moment. There is an Amount column and a Code column. I have a separate worksheet where a table contains the codes for credits and charges. As my macro runs down the main sheet line-by-line, validating the data, I need it to check these two cells on each line and perform actions based on the tests. Here is the formula from which I'm trying to build code.
Excel Formula:
=IF(NOT($D17=""),IF(OR(AND(COUNTIF(AdjCodes!$A:$A,$D17)>0,$C17>0),AND(COUNTIF(AdjCodes!$B:$B,$D17)>0,$C17<0)),"VALID","INVALID"),"INVALID")
The formula works as a test, but instead of putting Invalid or Valid in a cell, I want to highlight cells that are invalid and increase counters I have set up. As important, if not more so, is the order the tests are done. I'm confusing myself with all the If/Thens running through my head. The monetary tests are moot if the codes don't exist on the other sheet.
Should I be testing for correctness first in an IF statement of some kind so the tests only get done in the ELSE statement? For example: IF (the code is a charge AND the amount is over 0) OR (the code is a credit AND the amount is under 0), don't test anything else. ELSE run through the tests. Those are the only two ways this data is valid. How would I write that?
The tests I need to do if the pair are invalid are:
1) If the Amount cell is blank or 0.00, increase the invalid data count by one and highlight the amount cell.
2) If the Code cell is blank or doesn't exist in the Codes table on the AdjCodes sheet, increase the invalid data count by one and highlight the Code cell.
If those conditions exist, there is no point in checking for the "polarity" of the adjustment. Testing the Amount cells should be skipped to avoid marking one bad cell in two different counters (I think ).
3) If the code is in the Charge column of the Codes table, but the amount is less than 0.00, increase the Adjustment Mismatch count by one and highlight both cells
4) If the code is in the Credit column of the Codes table, but the amount is more than 0.00, increase the Adjustment Mismatch count by one and highlight both cells
I'm missing something. There appear to be overlaps in my tests.
Last edited: