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

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
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,981
Messages
6,122,566
Members
449,089
Latest member
Motoracer88

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