VBA Selection Resize by One Col Right

Bench

Board Regular
Joined
Aug 27, 2009
Messages
134
Hi,

Been trying to work out a selection macro.

The range to be selected is within a Pivot table and will be run monthly, so the range will grow in time.

The below works but it needs to extend one column further to the right.

The table is set up as follows:

A5 is Row Labels and B5 to the right is Months with Grand Total sitting in J4 (next month it'll be K4, the next L4 etc)

Any ideas, i've tried various offset and resizes but without any success. Imagine its something fairly easy that just needs adding to the end.

Thanks in advance

Ben

Code:
Sub Sealect()
Set rngData = Range(Range("A5"), Range("A5").End(xlToRight).End(xlDown))
    rngData.Select
End Sub
 

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Maybe try:

Code:
Sub Sealect()
    Set rngData = Range(Range("A5"), Range("A5").End(xlToRight).End(xlDown))
    rngData.Resize(, rngData.Columns.Count + 1).Select
End Sub

You may also want to look at the PivotTable's TableRange1 property in VBA Help.
 

Bench

Board Regular
Joined
Aug 27, 2009
Messages
134
Maybe try:

Code:
Sub Sealect()
    Set rngData = Range(Range("A5"), Range("A5").End(xlToRight).End(xlDown))
    rngData.Resize(, rngData.Columns.Count + 1).Select
End Sub

You may also want to look at the PivotTable's TableRange1 property in VBA Help.

Thanks this works perfectly, will look up that reference too.

Many thanks

Ben
 

Watch MrExcel Video

Forum statistics

Threads
1,122,481
Messages
5,596,399
Members
414,063
Latest member
N_Bates

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top