Solved

Excel VBA - Specify a specific column range to copy

Posted on 2014-04-29
3
1,169 Views
Last Modified: 2014-04-29
Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select

The above vba code will paint the range I need to copy.  However, I only want columns B:G instead of the "End(xlToRight).

How do I modify the above to paint all the row with data and columns B:G?

Thanks

Glen
0
Comment
Question by:GPSPOW
3 Comments
 
LVL 21

Expert Comment

by:Ejgil Hedegaard
ID: 40030862
Expect you start in column B

Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.Offset(0, 5)).Select

Open in new window

0
 
LVL 23

Accepted Solution

by:
Michael74 earned 500 total points
ID: 40030868
Try this
dim r as long
r = Range(Selection, Selection.End(xlDown)).row
Range("B" & Selection.row, "G" & r).Select

Open in new window


Note: It is always better to avoid using select as this will slow down the VBA considerably

Michael
0
 

Author Closing Comment

by:GPSPOW
ID: 40031057
Thanks

Glen
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

838 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