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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
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
I want to select with the macro so it can automatically be made into a histogram.

Andrew
 
Upvote 0
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
Maybe this?
Code:
Range("A1", Range("A" & Rows.Count).End(xlUp)).Select
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,591
Members
449,089
Latest member
Motoracer88

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