# Selecting a dynamic number of cells

#### akk

##### New Member
Hello,

If i have a set of data which changes size, so its in a single column and sometimes there are 30 cells with values sometimes theres more and sometimes less.

I understand i can count the cells with values but is there a way to have a macro select just the cells with values, this will be a single range (there are no gaps in the middle or anything), just varying in length?

I hope this is clear.

Many thanks,

Andrew

### Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

#### PCL

##### Well-known Member
What do you want to do with this set of data.
If you want to make calculation you could use the OFFSET function inside the calculation and use COUNTA function for the length of data.
Assuming data from A1 to ....
=SUM(OFFSET(A1,0,0,COUNTA(A:A),1))

#### akk

##### New Member
I want to select with the macro so it can automatically be made into a histogram.

Andrew

#### PCL

##### Well-known Member
Not sure to have understood your need but have a look in next code.
Assuming data starting from A2 going to .....
Next macro evaluate the last no empty cell ( the first no empty starting from the end) and make a selection.
Code:
``````Option Explicit
Sub Evaluate_Range()
Dim LASTROW  As Long
Dim MyRANGE As Range
LASTROW = Range("A" & Rows.Count).End(xlUp).Row
Set MyRANGE = Range(Cells(2, "A"), Cells(LASTROW, "A"))
MyRANGE.Select
'
End Sub``````

#### Peter_SSs

##### MrExcel MVP, Moderator
Maybe this?
Code:
``Range("A1", Range("A" & Rows.Count).End(xlUp)).Select``

Replies
3
Views
693
Replies
4
Views
312
Replies
6
Views
264
Replies
1
Views
283
Replies
9
Views
327

Threads
1,191,170
Messages
5,985,063
Members
439,938
Latest member
MAlhash

### 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

### 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