Trying to resize a selection

dudewheresmyvba

New Member
Joined
Jul 6, 2017
Messages
29
So I have stumbled my way through creating a range that will change with the size of the data I am using, but I am wanting to cut that down some in order to do some formatting. Specifically I want "MyRange" (currently using A1:L17) to not include the top row (1) or the bottom row (17), or the leftmost column (A).

I also need to select that last row and apply separate formatting to it as well.

As I am fairly new to this if there is some explanation to your solution that would be greatly appreciated.
 
Re: Resizing a selection, but offset is not working. Reference error?

Apologies @Joe4 and @RoryA.

As to what exactly is happening. The offset function is not applying any change to my selection. So my format changes apply to the whole A1:L17 not B2:L16 as intended.
Code is:

Range("A1").CurrentRegion.Select
Selection.Name = "MyRange"
Selection.Resize(Selection.Rows.Count + 5, Selection.Columns.Count + 0).Select
Selection.EntireRow.Hidden = False
Selection.Resize(Selection.Rows.Count - 5, Selection.Columns.Count + 0).Select




Dim MyRange As Range
Dim MyRange2 As Range
Dim LastRow As Long

Set MyRange = Range("MyRange")

' Exclude first and last row along with fist column
Set MyRange2 = MyRange.Offset(1, 1).Resize(MyRange.Rows.Count - 2, MyRange.Columns.Count - 1)
MyRange.Select


Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
and etc etc
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Re: Resizing a selection, but offset is not working. Reference error?

That code is applying the Offset and Resize to myRange, but putting the borders around Selection.
 
Upvote 0
Re: Resizing a selection, but offset is not working. Reference error?

Determine the original range.
Set the variable MyRange to that range.
Apply the .Offset and .Resize to MyRange
Put the borders around that.
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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