VBA loop empty cell validation

DFlem

New Member
Joined
Jul 20, 2022
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hi. I've been stuck on a portion of my code. I am attempting to loop through column B to find any empty cells, if the cell is empty then present msgbox then exit sub. If no cells are empty then once loop is complete present msgbox stating validation is complete. The error is when I run the code I automatically get the message box that no errors were found even though that is false. Please help if you can. I have attached the code I have written.

1672260581434.png
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Your code worked for me.
Are you sure the cells are empty, and do not contain any non-printable characters? When downloading from our mainframe, we'd get ASCII character 160 appended to text data. This looks like a space, but TRIM() doesn't clean it. The CLEAN() function doesn't remove it either. Go to the right of the apparent blank cell. Assuming cell B5 is the one you see as blank, enter =len(b5) in cell C5. If you see a number, then that could be what's causing your problem. To fix that particular problem, add an OR statement like this:

if range("B" & e).value = "" or Asc(range("B" & e)) >132 then

I've had problems with non-printable characters before.
 
Upvote 0
Your construction is working for me. (I suggest you enter the code using the VBA tags so people can copy it directly instead of posting an image.)

Your "empty" cells might not be truly empty. Use a LEN() function to check if they're truly a null value. Control characters or spaces might have crept in. If your work orders start with a specific set of alphanumeric characters then you might test for that as a positive indicator rather than a null value for a negative indicator.

Sorry, I see bbotzong's reply hit while I was running my test. I'm not sure how to delete this entry since it's redundant, but he has some good suggestions too.
 
Upvote 0
Your code worked for me.
Are you sure the cells are empty, and do not contain any non-printable characters? When downloading from our mainframe, we'd get ASCII character 160 appended to text data. This looks like a space, but TRIM() doesn't clean it. The CLEAN() function doesn't remove it either. Go to the right of the apparent blank cell. Assuming cell B5 is the one you see as blank, enter =len(b5) in cell C5. If you see a number, then that could be what's causing your problem. To fix that particular problem, add an OR statement like this:

if range("B" & e).value = "" or Asc(range("B" & e)) >132 then

I've had problems with non-printable characters before.
Thank you very much!
 
Upvote 0

Forum statistics

Threads
1,214,638
Messages
6,120,676
Members
448,977
Latest member
moonlight6

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