VBA to reduce selection by 1 row

KDavidP1987

Board Regular
Joined
Mar 6, 2018
Messages
51
Hello,

I am trying to find a way to reduce a selection of cells by 1 row, from the bottom, using VBA. The same way you could on a keyboard by holding shift and the up key. This action is performed repeatedly across several tables, and is needed to remove the totals row at the bottom after selecting down.

So far, my VBA looks like this, but the command I tried (in bold below) isn't working

Code:
    Range("B8:D8").Select
    Range(Selection, Selection.End(xlDown)).Select
[B]    Selection.Resize (Selection.Rows.Count - 1)[/B]
    Selection.Copy

I feel like a dunce, because I haven't been able to find a simple solution through google so far.

Any ideas?

Sincerely,
Kristopher
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
If the totals row is the very last row, try this:
Code:
Sub delRow()
    Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).EntireRow.Delete
End Sub
 
Upvote 0
If the totals row is the very last row, try this:
Code:
Sub delRow()
    Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).EntireRow.Delete
End Sub

Unfortunately, the data it's being copied off a pivot table. The final row can be selected, but not deleted from the data sets.

However, you did give me an idea... I can just remove the grand totals row from the pivot table settings, practically the same thing. Didn't think of that before, thank you so much!! :)

Out of curiosity though, is there no way to deselect 1 row from a selection using VBA??

Sincerely,
Kristopher
 
Upvote 0
I'm glad it worked out. :)

Try:
Code:
Selection.Resize(Selection.Rows.Count - 1, Selection.Columns.Count).Select
 
Upvote 0
Try:
Code:
Selection.Resize(Selection.Rows.Count - 1, Selection.Columns.Count).Select
You do not need to specify the row or the column argument if it is not changing (Resize only changes what you tell it to change); hence, this will also work...

Selection.Resize(Selection.Rows.Count - 1).Select
 
Last edited:
Upvote 0
Thanks for the update, Rick. :)
 
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,693
Members
449,117
Latest member
Aaagu

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