Extend Selected Cells in Excel VBA

Posted on 2012-09-07
Last Modified: 2012-09-07
Hi All,

Hopefully this is an easy answer, although searching Google and EE didn't help (maybe I was using the wrong search terms).

Anyway, using VBA I've ended up with a selection of cells from a Pivot Table. I would like to know how to extend the selection to include one more cell to the right please.

e.g. say I have A1to A10 selected, how would I programmatically extend the selection by one cell to the right so I end up with A1 to A11 selected?

I wish to add this extension selection to the PivotFields line below please.

    Dim pt As PivotTable
    Set pt = ActiveSheet.PivotTables(1)

Open in new window

Many thanks
Question by:jarrah10
    LVL 43

    Expert Comment

    by:Saqib Husain, Syed
    selection.resize(selection.rows, selection.columns+1).select
    LVL 43

    Expert Comment

    by:Saqib Husain, Syed
    Or simply

    selection.resize(, selection.columns+1).select

    You have to add this line after the select statement given in the question.

    Alternatively you can replace your select statement with this one
    LVL 43

    Expert Comment

    by:Saqib Husain, Syed
    LVL 43

    Accepted Solution

    Sorry, correction

    selection.resize(, selection.columns.count+1).select

    LVL 33

    Expert Comment

    Or this:
    Range(Selection, Selection.Offset(,1)).Select

    Open in new window

    LVL 1

    Author Closing Comment

    Perfect! Thanks very much. :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    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,…
    Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
    The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
    The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

    758 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

    10 Experts available now in Live!

    Get 1:1 Help Now