Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Trying to name a range of cells as "database" in a macro

Posted on 2001-07-26
3
Medium Priority
?
158 Views
Last Modified: 2010-05-02
When I try to name a range of cells as "database" in a marco sequence, Visual Basic gives me the following result:    

    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    ActiveWorkbook.Names.Add Name:="database", RefersToR1C1:= _
        "='2521'!R31C3:R6651C6"

My problem is I want to use the sequence with various different workbooks. This macro was created with an imported document named '2521' It seems if I want to use the macro with another document, Visual Basic still returns the information based on the earlier document namd.

I did select "relative reference" when I used the macro but that doesn't seem to solve the problem.

I would very much appreciate any help you could provide.

Thank you

Barry
0
Comment
Question by:BarryOTO
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
DennisBorg earned 200 total points
ID: 6324038
We can use the name of the active worksheet instead of that specific worksheet. Modify the last line as follows:

   ActiveWorkbook.Names.Add Name:="database", RefersToR1C1:= _
       "=" & ActiveWorksheet.Name & "!R31C3:R6651C6"


That should do the trick for you.


-Dennis Borg
0
 

Author Comment

by:BarryOTO
ID: 6335579
The answer gave me all the information I needed to solve my problem.
0
 
LVL 8

Expert Comment

by:DennisBorg
ID: 6378235
Thank you, Barry. I'm glad I could help.


-Dennis Borg
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question