jarrah10
asked on
Extend Selected Cells in Excel VBA
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.
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)
pt.PivotFields("Item").DataRange.Select
Many thanks
selection.resize(selection .rows, selection.columns+1).selec t
Or simply
selection.resize(, selection.columns+1).selec t
You have to add this line after the select statement given in the question.
Alternatively you can replace your select statement with this one
selection.resize(, selection.columns+1).selec
You have to add this line after the select statement given in the question.
Alternatively you can replace your select statement with this one
pt.PivotFields("Item").Dat aRange.res ize(,pt.Pi votFields( "Item").Da taRange.co lumns+1).S elect
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or this:
Range(Selection, Selection.Offset(,1)).Select
ASKER
Perfect! Thanks very much. :)