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
 

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Joined
Jul 30, 2006
Messages
3,656
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
 

d0wnt0wn

Well-known Member
Joined
Oct 28, 2002
Messages
771
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,670
Messages
5,597,483
Members
414,146
Latest member
marginmakerb

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