Adapting VBA Code to Exit Loop on encountered blank cell (Data Validation List)

Mitchx

New Member
Joined
Oct 20, 2021
Messages
24
Office Version
  1. 365
Platform
  1. Windows
Hello Guys,

I am using the code below to iterate through a data validation list, however in the data validation list there are a lot of blanks.
I wish to stop the loop when a blank row is encountered.

The code works perfect, but it keeps looping until infinity.
Does anyone have an idea what to add to stop the "next c" part when a blank value is encountered in the data validation list (so the InputRange)

Thanks in advance!



1634734856697.png
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hi Mitchx, welcome to Mr.Excel.

I would like to ask you to post your code using code tags instead of an image.

ScreenShot260.jpg



Then the volunteer helpers of this forum don't have to manually type your code all the way through to try things out.
Please take a look over here ...

 
Upvote 0
Welcome to the Board!

After this line:
VBA Code:
For Each c in inputRange
try adding this line:
VBA Code:
If c.value= "" Then Exit For

Also note GWteB's note on posting VBA code here.
If you use that tool to post your code in the future, it will make it much easier for us to copy your code and help you.
 
Upvote 0
Solution
Welcome to the Board!

After this line:
VBA Code:
For Each c in inputRange
try adding this line:
VBA Code:
If c.value= "" Then Exit For

Also note GWteB's note on posting VBA code here.
If you use that tool to post your code in the future, it will make it much easier for us to copy your code and help you.
Hey Joe,

You are a legend!

Thank you very much, it worked.
I have tried something like your solution, but I must have made a mistake somewhere.

Again thank you :)
 
Upvote 0
Hi Mitchx, welcome to Mr.Excel.

I would like to ask you to post your code using code tags instead of an image.

View attachment 49410


Then the volunteer helpers of this forum don't have to manually type your code all the way through to try things out.
Please take a look over here ...

Hi GWteB,

I am sorry, I will do that for future reference!
 
Upvote 0
You are welcome.
Glad we were able to help!
:)
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,558
Members
449,038
Latest member
Guest1337

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