Setting a named range with VBA

termeric

Active Member
Joined
Jun 21, 2005
Messages
280
I've used this code to set up a batch of names ranges on a spreadsheet, but am not sure how I would change this to set the rage as a full row instead of just as a cell? any advice on how I should tweak this?

Code:
Sub rangerset()

Dim cell As Range
Dim rng As Range
Dim RangeName As String
Dim CellName As String

Dim p As Integer
Dim chk As String

p = 181

Do Until p = 398

   RangeName = Sheets("input").Range("c" & p).value
   chk = Sheets("input").Range("j" & p).value

    
    'RangeName = "CkPG06a"
    'CellName = "C190"

    If chk = "x" Then

        Set cell = Worksheets("Input").row("c" & p)
        ThisWorkbook.Names.Add Name:=RangeName, RefersTo:=cell
    End If
    
    p = p + 1
Loop

End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
I've used this code to set up a batch of names ranges on a spreadsheet, but am not sure how I would change this to set the rage as a full row instead of just as a cell? any advice on how I should tweak this?

Rich (BB code):
Sub rangerset()

Dim cell As Range
Dim rng As Range
Dim RangeName As String
Dim CellName As String

Dim p As Integer
Dim chk As String

p = 181

Do Until p = 398

   RangeName = Sheets("input").Range("c" & p).value
   chk = Sheets("input").Range("j" & p).value

    
    'RangeName = "CkPG06a"
    'CellName = "C190"

    If chk = "x" Then

        Set cell = Worksheets("Input").row("c" & p)
        ThisWorkbook.Names.Add Name:=RangeName, RefersTo:=cell
    End If
    
    p = p + 1
Loop

End Sub
(Untested) Try changing the red highlighted line of code to this...

Set cell = Worksheets("Input").Rows(p)
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,320
Members
452,635
Latest member
laura12345

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