Trying to understand a line of code re: Dynamic Named Rangesfrom Mr Excel's textbook

I_Batman

Board Regular
Joined
Oct 14, 2011
Messages
62
This line of code is in Mr Excel's text VBA and Macro's Excel 2010 page 151.

It is in reference to storing a formula in a Name, and allows for a dynamic named column.

Code:
Names.Add Name:="ProductList", RefersTo:="=OFFSET(Sheet2!$A$2,0,0,COUNTA(Sheet2!$A:$A))"
I am trying to understand what precisely this line of code is doing.
From what I can glean on the Net, the OFFSET function can take 3, 4 or 5 variables, depending on what the user wants.
The last 2 optional variables define how many rows and columns of data the user wants the function to return. I assume this would be the equivalent to a Resize function.

I also understand from the Net that the COUNTA function returns the amount of cells in a column that contain data.
Am I correct on both assumptions?

If I am does that mean the line of code above uses 4 variables being:
a. The starting cell is Sheet2, cell A2
b. The function moves moves 0 rows
c. The function moves 0 columns
d. The function returns the amount of rows defined by the amount of cells in Sheet2, Column A?

And then the code refers all this back to a Name called ProductList?

Is that all accurate?
 
In your original code I get a compile error on this line:

Rich (BB code):
Worksheets("Expenses").Cells(ArrayRowCounter + 13, 2).Value = TotalforSpecificEXpense
I use Option Explicit and I recommend that you do too.

OK, I have never used it before, since I am struggling to learn VBA, clearly.
The web says it must be set up on a file level.

I typed it as first line immediately after

Sub GetEXpensesByDept.

I now get an error of Compile Error, Invalid Inside Procedure.
How do I set this up? The index in my text makes no reference to it.
 
Upvote 0

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I typed it as first line immediately after

Sub GetEXpensesByDept.

Option Explicit should appear as the very first line in each module. You will have to enter it manually in existing modules. For the future, you can do this in the Visual Basic Editor (VBE):

Tools > Options, and on the Editor tab, tick Require Variable Declaration. Thereafter it will appear automatically at the top of each new code module.
 
Upvote 0
Option Explicit should appear as the very first line in each module. You will have to enter it manually in existing modules. For the future, you can do this in the Visual Basic Editor (VBE):

Tools > Options, and on the Editor tab, tick Require Variable Declaration. Thereafter it will appear automatically at the top of each new code module.

Thanks, turned on now.
 
Upvote 0

Forum statistics

Threads
1,216,458
Messages
6,130,757
Members
449,588
Latest member
accountant606

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