Creating a named range of non-contiguous cells

NinaE_11

New Member
Joined
Aug 18, 2020
Messages
44
Office Version
  1. 2016
Platform
  1. Windows
Hello,

Can anyone give me advice on how to include 7 non-contiguous rows past my last row? I've tried .offset, but it's clear I'm not using it in the right place. I've gotten this far and stuck because the Offset command ends up moving down my range to start in cell A8.

Private Sub NamePERange()

Dim wsDest As Worksheet
Dim lr As Long
Dim MyRange As Range

Set wsDest = Workbooks("PE Table_SC.xlsm").Worksheets(1)
wsDest.Activate

'1. Find last used row in the copy range based on data in column A
lr = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Row

'2. Reset, Select Range and Name it 'PE'

Set MyRange = wsDest.Range("A1:L" & lr).offset(7)
ActiveWorkbook.Names.Add _
Name:="PE", _
RefersTo:=MyRange

End Sub

Any insight would be much appreciated - thank you!
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

StephenCrump

MrExcel MVP
Joined
Sep 18, 2013
Messages
4,124
Office Version
  1. 365
Platform
  1. Windows
I'm not sure what you mean by non-contiguous cells/rows in this context?

But I think you're looking for

VBA Code:
Set MyRange = wsDest.Range("A1:L" & lr + 7)
 
Solution

NinaE_11

New Member
Joined
Aug 18, 2020
Messages
44
Office Version
  1. 2016
Platform
  1. Windows
Thank you so much, StephenCrump! Worked perfectly.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,587
Messages
5,637,234
Members
416,963
Latest member
samfuge

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