VBA - Select Range for Pivot Table (Not including Last Row)

jhlim

New Member
Joined
Nov 30, 2019
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi Excel Experts,

I would like to have your advise on how to select range for a pivot table that not including the last row because it is the "Total". I tried below methods but not worked.

1) This method will including the row 6 (Final row-Total)
Selection.End(xlDown).Select
Range("A2:S2" & Range("B" & Rows.Count)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select

2) A5 may not always being the last 2 row data, sometime we could have until A7,A8
Range("A1").Select
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Range("A5").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlUp)).Select
Macro4.PNG


From the screenshot, I would like to select the range (C2:R5), the R5 would be variable (Sometime could be R6 or R7).

Thank you for your helps!!
 

Attachments

  • MAcro3.PNG
    MAcro3.PNG
    30.8 KB · Views: 6

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Not knowing what is in column B maybe...

VBA Code:
Sub chgRng()
Range("c2").CurrentRegion.Resize(Range("c2").CurrentRegion.Rows.Count - 1).Select
End Sub
 
Upvote 0
Not knowing what is in column B maybe...

VBA Code:
Sub chgRng()
Range("c2").CurrentRegion.Resize(Range("c2").CurrentRegion.Rows.Count - 1).Select
End Sub
Thank you Mark! It is works to select the range.
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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