Named Range in VBA

CEG

Board Regular
Joined
Jan 3, 2010
Messages
74
I have the following code:

Code:
With Worksheets("filtered")
                .Range("I12") = Worksheets("part number").Range("GN22")

The problem is that row is always changing, so I made a named range called "Subtotals" in the worksheet for that row so it is dynamic, but I don't know how to write the code so it will work. Here is what I have that doesn't work. I always need the column "GN" but the row will go up or down.

Code:
With Worksheets("filtered")
.Range("I5") = Worksheets("part number").Cells("Subtotals", "GN")
Thanks
CEG
 

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.
Try...

Code:
Sub test()
Dim Subtotals As Range
Sheets("filtered").Range("I5") = Sheets("part number").Range("Subtotals")
End Sub
 
Upvote 0
I guess to rephrase this, I made a row a named range, lets say row 23. Now, it will not always be row 23. So, right now the range is GN23, but tomorrow it could be GN34. Since I have about 20 of these I need to keep track of, I thought the best thing to do was make one row a named range, instead of making about 20 single cells named ranges.
 
Upvote 0
CEG,

Your named range "Subtotals" uses which columns?

Say it is at columns GL:GN

If you need always refer to column GN (the third column in the named-range in my example) maybe something like

Range("Subtotals").Cells(1,3)

HTH

M.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,522
Messages
6,114,112
Members
448,549
Latest member
brianhfield

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