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
 

Some videos you may like

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

RalphA

Well-known Member
Joined
May 14, 2003
Messages
3,829
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.
 

chatguy

New Member
Joined
Oct 15, 2007
Messages
10
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
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
22,960
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.
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
43,479
Office Version
365
Platform
Windows
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
 

chatguy

New Member
Joined
Oct 15, 2007
Messages
10
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
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
22,960
If Conditional Formatting is sufficiant notice of a temporary mismatch, the same formulas could be used for that.
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
43,479
Office Version
365
Platform
Windows
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?
 

chatguy

New Member
Joined
Oct 15, 2007
Messages
10
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
 

Forum statistics

Threads
1,089,507
Messages
5,408,691
Members
403,224
Latest member
rholmesa

This Week's Hot Topics

  • help please
    SORRY NOT ANY GOOD AT EXCEL SO HELP WOULD BE MUCH APPRECIATED this formula is in a sheet called ignore...
  • two formulas needed
    Hello, I'll try my best to explain this: First formula needed in Sheet1 cell A2: If Sheet1 cell B2 = Sheet2 cell B2 then return a 1. If not then...
  • Dynamic Counts
    Good afternoon, we are tidying up some data & the data seems to be growing quicker than we are tidying it up! What we confirm (by reviewing it...
  • Help Excel formula eliminate duplicate values and keep only 2 identical rows.
    as picture below column A has a duplicate value. but the values are not the same as the rule. sometimes 4 rows, sometimes 10 rows or 7 or 9...
  • Macro Compile Error Sub or Function not defined
    Hello, I am trying to run macros from a validation list, all macros have been created and run perfectly on there own but I'm getting a compile...
  • Last row combined with Current Region VBA
    I'm generally happy finding the last row of data through something like Lastrow = Cells(Rows.Count, "D").End(xlUp) but I don't always receive data...
Top