Solved

VBA Select Range when rows and columns are dynamic

Posted on 2012-03-17
3
283 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

789 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