Solved

VBA Select Range when rows and columns are dynamic

Posted on 2012-03-17
3
281 Views
Last Modified: 2012-06-22
I would like to create a macro that will select the range based on the following:
1) Upper left is determined by wherever the curser is placed when the macro is executed.
2) Lower right is determined by last row with data in COL A and last column with a header.

The macro will be executed on the active worksheet in whatever workbook is open.

For example, this code gives me lots of empty records:     Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select

Thanks for your help, Experts!
0
Comment
Question by:thutchinson
  • 2
3 Comments
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 37732676
Try this.
LastRow = Range("A" & Rows.Count).End(xlUp).Row
LastCol = Cells(1, Columns.Count).End(xlToLeft).Column

Range(ActiveCell, Cells(LastRow, LastCol)).Select

Open in new window

0
 

Author Comment

by:thutchinson
ID: 37732696
That's fantastic.  Thanks very much.
0
 

Author Closing Comment

by:thutchinson
ID: 37732698
Quick reply, great answer. in a word, "Perfect!"
0

Featured Post

Highfive Gives IT Their Time Back

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

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

12 Experts available now in Live!

Get 1:1 Help Now