Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

currentregion property

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » CurrentRegion Property

CurrentRegion Property

ResolvedVersion 2007

Steve has attended:
Excel VBA Intro Intermediate course

CurrentRegion Property

Anthony,

Excellent course last week. I raised the issue of the use of a range reference in conjunction with the CurrentRegion property. The line of code you were using was:
Sheets("MyData").Range("A2").CurrentRegion.......
Although Range A2 has been specified as the starting point from which to capture the data, this is being ignored and all data in the sheet starting from range A1 is being selected.
How do you overcome this to capture all data in a sheet starting at a specific cell.
Thanks.

RE: CurrentRegion Property

Hello Steve,

There are numerous ways to achieve what you are asking. The problem we have is CurrentRegion is reliable in selecting a range even if there are missing cell entries, but it selects the top row despite setting the starting cell as A2. This is because CurrentRegion will select across and down until it finds an entire empty column or row.

One way to work around this is to try the following code. It selects everything, counts the rows and deducts 1, this value is stored in variable.
We then use the resize and offset commands with this variable. This would work.
Dim counter As Integer

counter = Range("A2").CurrentRegion.Rows.Count - 1

Range("a1").CurrentRegion.Resize(counter).Offset(1, 0).Select


Some may ask why we don't just use the xlDown command, this would only work if the colulmn we are selecting down does not have any missing cell entries!

I hope this resolves your question. If it has, please mark this question as resolved.

If you require further assistance, please reply to this post. Or perhaps you have another Microsoft Office question?

Have a great day.
Regards,

Mark
Microsoft Office Specialist Trainer

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Colouring cells containing formulas

Cells in a worksheet can contain values or they can contain formulas. You may wish to identify all the cells in your worksheet that contain formulas by colouring those cells.

Follow these steps:
1. Choose Edit > Go To menu, or press either F5 or Ctrl+G. Excel displays the Go To dialog box.
2. Click Special. Excel displays the Go To Special dialog box.
3. Select the Formulas radio button option.
4. Select OK.

At this point, every formula cell in the worksheet is selected, and those cells can be coloured formatted as desired.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.