Check if 2 commas exist

Nichole09

Board Regular
Joined
Aug 27, 2016
Messages
132
Hello!!

Is there a way to check if two commas exist in a cell? In cell H3 of my worksheet users will enter an address and I want to make sure they use two commas when entering an address as another sheet takes this address and splits it. for example: 123 ABC st Moraga CA 97501 should read, 123 ABC st, Moraga, CA 97501. If the user does not enter two commas in cell H3 I would like a msgbox to appear instructing the user to enter a comma after the street address and after the city and the cell contents to be cleared.

possible workaround: the reason for this, is another sheet splits this address up to show the street address in one cell, and the cell below that will contain the city, state and zip. I haven't found a way using a formula or vba to split the address without the use of commas. As sometimes there will be a city with two names and every street address entered could be different. Using commas seemed to be the best solution, unless someone can provide another solution?

Any help would be greatly appreciated!!
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
You could use this Data Validation formula...

=LEN(H3)-LEN(SUBSTITUTE(H3,",",""))=2
 
Upvote 0
You could use this Data Validation formula...

=LEN(H3)-LEN(SUBSTITUTE(H3,",",""))=2


This is really Cool! I actually have never used a formula for data validation. This works perfectly! Is there a way to clear the contents if this error message appears? Perhaps a macro to run if this error message pops up?
 
Upvote 0
This is really Cool! I actually have never used a formula for data validation. This works perfectly! Is there a way to clear the contents if this error message appears? Perhaps a macro to run if this error message pops up?
You would need remove the Cell Validation and use VBA event code to do that, but I'm curious... why would you want to clear the cell? The idea of warning the user and allowing him/her to see what was typed is two-fold... first, it allows the user to review what he/she typed to see where they went wrong and, second, it allows the user to edit the cell without having to type the entire entry over again.
 
Upvote 0
This is a very good point! Having read this it makes the most sense to leave it be. I tried to incorrectly type in the address and did not realize this error message would continue to appear. I was worried they could click out of this message and perhaps forget to make corrections. If a user where to not make this correction the address would not split correctly on another sheet. This sheet gets printed as a PDF then emailed to another company. So I was worried of the address missing characters. After attempting to enter the address incorrectly (more than once this time) I noticed this error will continue to pop up. This is certainly the better way to go! Thank you Rick!!
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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