Selecting a dynamic number of cells

akk

New Member
Joined
Mar 19, 2009
Messages
36
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
Joined
Jul 15, 2008
Messages
1,356
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))
 
Upvote 0

akk

New Member
Joined
Mar 19, 2009
Messages
36
I want to select with the macro so it can automatically be made into a histogram.

Andrew
 
Upvote 0

PCL

Well-known Member
Joined
Jul 15, 2008
Messages
1,356
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
 
Upvote 0

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
59,294
Office Version
  1. 365
Platform
  1. Windows
Maybe this?
Code:
Range("A1", Range("A" & Rows.Count).End(xlUp)).Select
 
Upvote 0

Forum statistics

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

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
Top