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

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

jeffreybrown

Well-known Member
Joined
Jul 28, 2004
Messages
5,147
Try...

Code:
Sub test()
Dim Subtotals As Range
Sheets("filtered").Range("I5") = Sheets("part number").Range("Subtotals")
End Sub
 

CEG

Board Regular
Joined
Jan 3, 2010
Messages
74
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.
 

Marcelo Branco

MrExcel MVP
Joined
Aug 23, 2010
Messages
17,017
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
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:
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,598
Messages
5,832,645
Members
430,150
Latest member
amitk1

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