Solved

VBA Select Range when rows and columns are dynamic

Posted on 2012-03-17
3
287 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 34

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

636 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