Does 'CurrentRegion' Include Cells With Formulas?

DerekK

Board Regular
Joined
Jun 18, 2007
Messages
90
Office Version
  1. 2003 or older
Platform
  1. Windows
I'm testing out some VBA on a sheet with only two rows: one row for headings, one row for data.

My VBA includes a For Each statment with a CurrentRegion property but the code seems to search the entire sheet, rather than just the "CurrentRegion." I know this because I've included an If Then statement with Else MsgBox "Not applicable" and it seems to want to display this message a full 65,536 times!

Therefore, might "CurrentRegion" include any formulas, as I have formulas copied all the way down to the last row? If so, how do I make sure the For Each applies only to rows where I have actual data?

If not, then what might be the problem?

Hope you can help...



-Derek
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
CurrentRegion should include everything until a blank row and column. So yes it appears your problem is having formulas "all the way".

You could most simply exclude "blank" formulas with an if check against the cells .Value property. It will still go through them but you shouldn't notice it.
I think UsedRange would operate under a similar limit as well. I think it includes formatted cells as well.
 
Upvote 0
Kiitos, jollaisia sir

I wound up substituting "End(xlUp)" in the code and it worked perfectly!
 
Upvote 0

Forum statistics

Threads
1,214,791
Messages
6,121,611
Members
449,038
Latest member
apwr

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