Solved

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

Posted on 2001-07-26
3
148 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 50 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now