adjust code to make range dynamic

d0wnt0wn

Well-known Member
Joined
Oct 28, 2002
Messages
771
is there any way that this can be adjusted so the named range that is created is dynamic?

With Worksheets("Score sheet").Range("Dn1:Dn17")
For Each oneCell In .Cells
On Error Resume Next
If oneCell.Text <> vbNullString Then
.Offset(2, oneCell.Row).Resize(17, 1).Name = oneCell.Text
End If
On Error GoTo 0
Next oneCell
End With

End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
d0wnt0wn,

The following will look for the last row of data in column Dn, from the last row of the worksheet, up.

Try:

Code:
  With Worksheets("Score sheet").Range("Dn1", Range("Dn" & Rows.Count).End(xlUp))
    For Each oneCell In .Cells
      On Error Resume Next
      If oneCell.Text <> vbNullString Then
        .Offset(2, oneCell.Row).Resize(17, 1).Name = oneCell.Text
      End If
      On Error GoTo 0
    Next oneCell
  End With


Have a great day,
Stan
 
Upvote 0
hi stanley... i should have been a bit more clear...... and i left out a bit of code that may have confused.

dim onecell as range
With Worksheets("Score sheet").Range("Dn1:Dn17")
For Each oneCell In .Cells
On Error Resume Next
If oneCell.Text <> vbNullString Then
.Offset(2, oneCell.Row).Resize(17, 1).Name = oneCell.Text
End If
On Error GoTo 0
Next oneCell
End With

End Sub

dn1:dn17 is a range of a preset list..... this i do not need to make dynamic..... but what the code does is it takes the names in dn1 to dn17 and creates named ranges with the same names in the list and they refer to dq2:dq17,dr2:dr17 etc (depending how many new ranges there are)..... its the dq and dr and etc ranges that I want to be dynamic
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,384
Members
449,080
Latest member
Armadillos

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