Select Columns from Seletced Cell Range on Excel 2010 with VBA

Posted on 2012-09-07
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)?


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!
Question by:jarrah10
    LVL 39

    Accepted Solution



    or directly


    LVL 92

    Assisted Solution

    by:Patrick Matthews
    No need to select that range.  Try:


    Open in new window

    LVL 1

    Author Closing Comment

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

    Thank you very much!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
    INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
    The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
    This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

    759 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

    9 Experts available now in Live!

    Get 1:1 Help Now