Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Changing Range References with VBA

Changing Range References with VBA

Changing Range References with VBA

OK.  I have two worksheets in a workbook, "OSBL" and "OSBLData".  The OSBLData sheet is full of information that I retreived from an Access database.  Excel automatically refers to the data that Access has provided me by the range name "ExternalData1".  I want to lookup information on the OSBL sheet from "ExternalData1".  The problem is that my lookupvalue consists of a combination of the data in the first two columns that Access has returned.  So, I inserted a column to the left of the data and entered the formula =B2&C2 in cell A2 and copied it down.  This gives me my list of unique values that I can then use with the VLOOKUP function.  Now my range "ExternalData1" only refers to columns B,C,D... while the values I am looking up are in column A.  So I redefine the range "ExternalData1" to include column A.

The reason I did all this was that the "ExternalData1" range will automatically resize every time I refresh the data that is being returned from Access.  This is extremely useful for the hundred of formulas I have on the sheet "OSBL".

Does anyone know of a way that I can use VBA to automatically redefine the range one column to the left when I click the refresh data button on the external data toolbar?  If this is too much of a pain, how about just a VBA procedure that will do it that I could assign to a button?  It's no problem for me to redefine the range, but the other users of the spreadsheet will likely destroy all my work if I ask them to do anything more than click a button...

Thanks in advance,


RE: Changing Range References with VBA

Large amount of data is usually easier to handle in a database.

Why dont you just keep the data in access and use this program?

Best Regards


RE: Changing Range References with VBA

I've got some major math I am trying to do to this, plus I am working off a database that our IT department set up and locked so that we have a difficult time modifying certain aspects.

I did manage to find a good way to deal with this.  I set up a query in Access that combined the information in column B and C.  I then changed my "Get External Data" information in Excel to look up this information instead.  This returned the data I needed in the format I needed.

The original problem still stands.  I would be interested in knowing how to reference any of the ranges that Excel automatically creates and then make a slight modification.  I think this could be quite useful.

RE: Changing Range References with VBA

If you have continious data (no empty cells) at least in the first row and in the first column then you can use dynamic ranges. After inserting the column and filling it with data run macro:

Sub DefineRangeName()

ActiveWorkbook.Names.Add Name:="datarange", RefersToR1C1:= _

End Sub

This way datarange will always start from cell A1 (until the next column-insert).

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close