?
Solved

Select Columns from Seletced Cell Range on Excel 2010 with VBA

Posted on 2012-09-07
3
Medium Priority
?
612 Views
Last Modified: 2012-09-10
Hi All,

Let's say I have cells C3 to T3 selected as a result of VBA code that selects the DataRange on a PivotTable (code below). How would I then translate this to select all columns between C and T please (so that I can autofit them)?

pt.PivotFields("Item").DataRange.select

The above code just selects a range of cells, so I would like to take this range and apply it to all columns within the same range please.

Many thanks!
0
Comment
Question by:jarrah10
3 Comments
 
LVL 39

Accepted Solution

by:
nutsch earned 1000 total points
ID: 38377799
Try:

pt.PivotFields("Item").DataRange.entirecolumn.select

or directly

pt.PivotFields("Item").DataRange.entirecolumn.autofit

Thomas
0
 
LVL 93

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 1000 total points
ID: 38377804
No need to select that range.  Try:

pt.PivotFields("Item").DataRange.EntireColumn.AutoFit

Open in new window

0
 
LVL 1

Author Closing Comment

by:jarrah10
ID: 38382555
Thanks, you both posted just the answer I needed within 30 seconds of each other so only fair to split the points.

pt.PivotFields("Item").DataRange.EntireColumn.AutoFit
                                       
Thank you very much!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
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.

839 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