Solved

EXCELL VBA cell reference

Posted on 2013-01-15
4
379 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 200 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 150 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 150 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 18

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

Technology Partners: 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

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 how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

690 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