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
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
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.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,557
Messages
6,114,293
Members
448,564
Latest member
ED38

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
Back
Top