How To Detect When # Of Characters In One Column Does Not Match # Defined In Other Column

chatguy

New Member
Joined
Oct 15, 2007
Messages
10
Hi All,

I'm hoping this would be easy to do, but would anyone be able to figure out how to create a macro that:

- In each row, pops up a Warning Dialog Box if the amount of letters in column "J" doesn't match the # defined in column "B"?
- Preferably this would pop up the Dialog Box as soon as the error occurs (so it's always running)

Two Exceptions:
- Does not look at Rows 1 & 2
- Does not look at Rows where column B = 0 or null

Thanks so much!
CG
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Here's one way:
Highlight J3:J300 (assuming row 300 is the last row you will use)
click on Format, Conditional formatting..., select "Formula is:", and enter:
=(B3<>"")*(B3<>0)*(LEN(J3)<>B3)
Clickl on Format, select Patterns, select a color (I chose red), then OK, OK.
NOTE: The above solution will work only if cells in column J have letters or stsrings. It will not work for numbers.
 
Upvote 0
Hi Ralph,

I wish I could do conditional formatting. Unfortunately there is conditional formatting already being used in this column, different colors depending on the content.

That's why unfortunately it'll still need to be a macro with a pop-up warning message, if you or anyone else would happen to know how to make a macro that does that? (I'm just hoping it won't be a hard macro to do)

Oh well...(on the bright side, you gave me an idea for a different project, thanks for the info though) -CG
 
Upvote 0
Validation would do what you want.
Select J3 and enter the validation formula
=OR($B3=0,LEN($J3)=$B3)
copy that Validation to the rest of the cells in column J.
That will notify the user when an entry when an entry to column J is not good.

Put the same validation formula on B3 and a bad entry into column B will trigger a message.

The error message can be customized.
 
Upvote 0
Another non-macro solution is to use a formula. Formula in K3 copied down.

Excel Workbook
ABCDEFGHIJK
1AllowedMyCheck
2LengthValuesLength
35happy 
44sadError
50whatever
62hi
7
81hoError
913what is this?
Wrong Length
 
Upvote 0
Thanks everyone,

So far, if nothing else can be done by way of a VB macro, I might use Peter's reply since I can use a column to the right of the used column. Not an ideal solution since we wouldn't want to clog up the screen (it already is very clogged!) but is the most adaptable for this spreadsheet.

Mike's, while it does sound good, unfortunately wouldn't work for this application, since temporarily if the amount of letters are wrong, it would be nice if that were "allowed", but I would need it to quickly notify the user with a popup as soon as they enter the error, just so they are aware of it. But I'd have to allow them to enter the error, since they may not be done entering all of the letters. (A letter is entered when a specific item "passes" or "fails", so it would be a "P" or "F" entered.)

And thanks so much Mike, Peter and Ralph. Ralph- I've already got an idea for a different application that would use your suggestion, and Mike, your suggestion opened my eyes to validation that can be used to make sure that simply only Ps or Fs can be entered in that column (I never thought of that!).

If anyone has any Visual-Basic Macro solutions, if it's not too much trouble, I'd still welcome those!

Thanks,
CG
 
Upvote 0
If Conditional Formatting is sufficiant notice of a temporary mismatch, the same formulas could be used for that.
 
Upvote 0
chatguy

How is column J populated? Keyboard entry by the user?, Formula?, vba code? Something else?

Could somebody be pasting a series of values into the column at once?
 
Upvote 0
chatguy

How is column J populated? Keyboard entry by the user?, Formula?, vba code? Something else?

Could somebody be pasting a series of values into the column at once?

Hi Peter,

It's usually done by hand (keyboard entry by user). It basically consists of the letters P & F (pass or fail). Basically column B says how many P/F's are expected, but if column B=5 on one row, it could be possible that there are 4 P's in column J (since they didn't get around to checking the last/5th item yet).

In this case, it would be nice to alert them with a popup (just one) as soon as the incomplete field is entered. It could also be possible that someone enters 6 P's instead of 5, which makes things even more confusing.

...actually, I oversimplified the case above, there are really more letters than P and F (total of 7) and conditional formatting is used depending on the contents of the field (ex: one color if one part fails, if multiple fails, if all fails, if all passes, etc) so using conditional formatting in this case would be pretty confusing to add another color. Since there are columns in use all around it, coloring a nearby column would be pretty tough as well, where it's become a whole colorful sheet through years of changes, etc. Since this has become a bigger problem with the spreadsheet, unfortunately I'd need to resort to popup dialogs to notify the user.

In the worst case scenario, if a macro cannot be done, I've tried a modification of the formula you've provided and seems to work well (btw, thank you so much!!)...I'd just need to scroll all the way to the right to see the results after I notice that something looks off. So if the numbers don't match up, at least I can now find the problem quickly, if I do that. So although it works, it would be nice if it caught the user's attention as soon as the error is made.

The one other issue I've noticed when using a formula instead of a global macro, is that the filesize went up by another 3.5MB (pretty big!) due to its repetition all throughout the workbook (this formula is currently repeated on about 30 pages!). So I was hoping that a macro that constantly checks each page as soon as a change it made would bring down the filesize as well--although I do understand that it would probably use more CPU each time a change is made. Hard drive space is probably more valuable than CPU usage, however, which would favor a macro, if this is possible(?).

Thanks
CG
 
Upvote 0

Forum statistics

Threads
1,213,495
Messages
6,113,992
Members
448,538
Latest member
alex78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top