ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to reference a named area (https://www.excelbanter.com/excel-programming/394693-how-reference-named-area.html)

Orlando

How to reference a named area
 
HI, programming in excel VBA, how can I make reference to and area I define,
example I name the area D5 to F10 and I call it Salary, how can I read the
information in the cell D5 or E8 from VBA.

Thanks.

JMB

How to reference a named area
 
try:
MsgBox Range("Salary")(1, 1).Value
MsgBox Range("Salary")(4, 2).Value


"Orlando" wrote:

HI, programming in excel VBA, how can I make reference to and area I define,
example I name the area D5 to F10 and I call it Salary, how can I read the
information in the cell D5 or E8 from VBA.

Thanks.


OssieMac

How to reference a named area
 
Hi orlando,

I'm not sure if you are referring to a range which you have named in the
interactive mode or a range to which you have assigned to a variable in VBA.

I suggest that you copy the following code into a blank workbook and check
out what it all does.

Macro1 starts with recorded code of naming a range while working on the
worksheet. The Named range could have been created previously but I have put
it in the macro so that you have the range named properly for the following
code.

Run the macros in order by number.

Macro2 then puts some data in the cells in the named range. Note that the
named range is like a mini worksheet within a worksheet and the cells start
on row1, column 1 of the named range. When using the cells function, note
that the row number is first and the column number second. Cells(RowNumber,
ColumnNumber).
This is opposite to range("A1") where column number is first.

Comments in the other macros say what they do.

I have included code which inserts data, reads data and loops through all
the cells in the range.

Macro5: Lastly, I have included code to assign a range to a VBA variable and
then loop through the cells and write data to them.

Hope this helps and feel free to get back to me if you have any more
questions.

Regards,

OssieMac



"Orlando" wrote:

HI, programming in excel VBA, how can I make reference to and area I define,
example I name the area D5 to F10 and I call it Salary, how can I read the
information in the cell D5 or E8 from VBA.

Thanks.



All times are GMT +1. The time now is 05:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com