VBA to select range of cells from A2 to ........

Can an Expert provide me with the VBA code I need to select a range of cells from A2 but where the end cell could change so it could be AM500 or AT1000 etc etc

Thanks
JagwarmanAsked:
Who is Participating?
 
Saqib Husain, SyedConnect With a Mentor EngineerCommented:
Then try

Range(Range("A2"), Cells.SpecialCells(xlCellTypeLastCell)).Select
0
 
Alexander Eßer [Alex140181]Software DeveloperCommented:
a row based selection might look like this:
Range(Selection, Selection.End(xlToRight)).Select

Open in new window

whereas "Selection" could be "Range("A2")"
0
 
Saqib Husain, SyedEngineerCommented:
Range(Range("A2"), Cells.Find("*", Range("A1"), , , , xlPrevious)).Select
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
Rob HensonFinance AnalystCommented:
Assuming continuous data in at least one row and one column:

Range("A2").Select
CurrentRegion.Select


CurrentRegion.Select is equivalent to keyboard selection of "Ctrl + *"

Thanks
Rob H
0
 
JagwarmanAuthor Commented:
Rob H

Unfortunately there are some columns with nothing in them so this does not work on my current file.
0
 
JagwarmanAuthor Commented:
ssaqibh

this a,most works but for some reason it goes to AK but there is data in AL which it is not capturing ???
0
 
JagwarmanAuthor Commented:
Alex140181 this does not work for me because there are blank rows in between. but thanks for trying
0
 
Rob HensonFinance AnalystCommented:
Do the empty columns have a header? If they do then it should still work as the header row is constant. If not, hence why the EndRight suggestion doesn't work.

Would inserting just a # or just a space in the relevant columns be a workaround; just to populate these columns so that the columns beyond these get included in current region?

If populated the EndRight would also then work.

Thanks
Rob H
0
 
JagwarmanAuthor Commented:
Rob H

I do use that in other circumstances but it won't work in this one but thanks for trying.
0
 
JagwarmanAuthor Commented:
Exactly what I was looking for. Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.