Find non-blank cells in range without for loop

Prevost

Board Regular
Joined
Jan 23, 2014
Messages
198
Hey There. I have a general question. I find myself using the 'For Each' loop when going through either user selected ranges or pre-defined ranges to find cells that have specific values, are blank, or are non-blank. Is there a more efficient way to accomplish this?

For example, I have a range "F2:F21" that I want to look through to find non-blank cells. When there is a non-blank cell, I am then using the information from that cell and cell offsets and exporting it into a new sheet in a new workbook. Is there a way to accomplish this without 'For Each' loops by using a built in excel function or something? I don't know which is why I am asking.

Thanks for any input!
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I recently ran into a similar issue and had been prone to using "For" loops to solve most issues. Have you tried using AutoFilter or Advanced Filter in your code? That will drastically cut down on the time it takes to process large datasets, depending on your needs.

Check this out: Range.AutoFilter Method (Excel)
 
Upvote 0
Hey There. I have a general question. I find myself using the 'For Each' loop when going through either user selected ranges or pre-defined ranges to find cells that have specific values, are blank, or are non-blank. Is there a more efficient way to accomplish this?

For example, I have a range "F2:F21" that I want to look through to find non-blank cells. When there is a non-blank cell, I am then using the information from that cell and cell offsets and exporting it into a new sheet in a new workbook. Is there a way to accomplish this without 'For Each' loops by using a built in excel function or something? I don't know which is why I am asking.
It will be much easier to give you a usuable answer if you tell us the offsets from Column F that you want to copy (not export) to a new sheet in the new workbook. Also, does this new workbook already exist or is it being created "on the fly"?
 
Upvote 0
I am not sure the Autofilter method is what I am looking for unfortunately...I have my code working with the For Each loop and then copying certain offset values. The actual value of the offsets is not important. If I want to go through the range and have excel know which cells are non-blank and then those cells which are not blank, use the certain offset values (and get the row value). That's what I was sort of wondering, however I think that I don't know enough about VBA to know if this is possible or give a more specific direction. Thanks.
 
Upvote 0

Forum statistics

Threads
1,216,095
Messages
6,128,794
Members
449,468
Latest member
AGreen17

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