Solved

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

Posted on 2013-12-10
10
323 Views
Last Modified: 2013-12-10
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
0
Comment
Question by:Jagwarman
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 13

Expert Comment

by:Alexander Eßer [Alex140181]
ID: 39708549
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
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39708565
Range(Range("A2"), Cells.Find("*", Range("A1"), , , , xlPrevious)).Select
0
 
LVL 31

Expert Comment

by:Rob Henson
ID: 39708790
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
 

Author Comment

by:Jagwarman
ID: 39708875
Rob H

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

Author Comment

by:Jagwarman
ID: 39708883
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Jagwarman
ID: 39708952
Alex140181 this does not work for me because there are blank rows in between. but thanks for trying
0
 
LVL 31

Expert Comment

by:Rob Henson
ID: 39709075
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
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
ID: 39709082
Then try

Range(Range("A2"), Cells.SpecialCells(xlCellTypeLastCell)).Select
0
 

Author Comment

by:Jagwarman
ID: 39709105
Rob H

I do use that in other circumstances but it won't work in this one but thanks for trying.
0
 

Author Closing Comment

by:Jagwarman
ID: 39709109
Exactly what I was looking for. Thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now