Solved

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

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…

803 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