Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

EXCELL VBA cell reference

Posted on 2013-01-15
4
Medium Priority
?
384 Views
Last Modified: 2013-01-24
I am sure that this is an easy question, so here goes.

Currently in VBA i can reference a cell as (useing cell H8 as an example)

[H8]

Open in new window


or as
ActiveSheet.Range("H8").Text

Open in new window


However if i insert a column before column H then all the VBA's go out of whack.

Is there a way that i can name the columns and then refer to them by their name so that a column add/remove isnt breaking all the scripts? if it helps each column in row 1 holds the Unique identifyer for that column (Name, Address, Phone, etc....)

Cheers for any solutions.
0
Comment
Question by:Andrew Davis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 18

Accepted Solution

by:
krishnakrkc earned 800 total points
ID: 38781510
You can use

MsgBox Range("Name").Column >> returns Column Number
MsgBox Range("Name").Address >> returns Range Address

where "Name" is a name range.

Kris
0
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 600 total points
ID: 38781591
try this

Sheets("Sheet1").Range("Employees").Cells(4, 1).Text

refer
http://stackoverflow.com/questions/11966342/vba-excel-rename-columns-for-easy-referencing
0
 
LVL 24

Assisted Solution

by:Steve
Steve earned 600 total points
ID: 38781612
You can find the column in which the word "Name" first appears and use that in the range/cell refs:

NameColumn = ActiveSheet.Cells.Find(What:="Name", After:=ActiveSheet.Range("A1"), SearchOrder:=xlByColumns, SearchDirection:=xlNext).Column

ActiveSheet.Cells(8,NameColumn).Text ' will reference row 8 in the name Column

Open in new window

0
 
LVL 19

Author Closing Comment

by:Andrew Davis
ID: 38817100
Hey guys thanks for your help. All answers were good and correct, got something from each of them, Split points, with slightly more for first answer, for no other reason than Kris was the quickest to post ;)

Cheers.
Andrew
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

610 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