PC Review


Reply
Thread Tools Rate Thread

Dealing with column headers

 
 
Pawan
Guest
Posts: n/a
 
      26th Aug 2008
Hi...

I am learning about writing macros. I always stuck up at one point.
I need to do various activies on columns based on their headings. e.g. I
have to replace all "NA" in the column whose heading is "TOWN". Currently I
write the macro using column number. But if the columns gets shifted, then
this macro will not work. How can I extract column number by identifying its
heading?

Regards,
Pawan
 
Reply With Quote
 
 
 
 
New Member
Join Date: Nov 2007
Location: Lincoln, UK
Posts: 18
 
      26th Aug 2008
try this

for x = 1 to columns.count
if columns(x).cells(1).value2 = YourValue then exit for
next x

x is then the column number so you would reference as such columns(x)

To go one step further you could wrap this in a function

public function get_column(byval YourValue as string) as integer
for x = 1 to columns.count
if columns(x).cells(1).value2 = YourValue then
get_column = x
exit function
end if
next x
end function

HTH
 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      26th Aug 2008
colNo = Application.Match("TOWN",Rows(1),0))

and use colNo.


--
__________________________________
HTH

Bob

"Pawan" <(E-Mail Removed)> wrote in message
news:CB79315B-1E8E-4CB1-96D6-(E-Mail Removed)...
> Hi...
>
> I am learning about writing macros. I always stuck up at one point.
> I need to do various activies on columns based on their headings. e.g. I
> have to replace all "NA" in the column whose heading is "TOWN". Currently
> I
> write the macro using column number. But if the columns gets shifted, then
> this macro will not work. How can I extract column number by identifying
> its
> heading?
>
> Regards,
> Pawan



 
Reply With Quote
 
New Member
Join Date: Nov 2007
Location: Lincoln, UK
Posts: 18
 
      26th Aug 2008
lol good point bob. no point reinventing the wheel!
 
Reply With Quote
 
Pawan
Guest
Posts: n/a
 
      26th Aug 2008
Thats perfect...

Thanks Bob.. :-)

"Bob Phillips" wrote:

> colNo = Application.Match("TOWN",Rows(1),0))
>
> and use colNo.
>
>
> --
> __________________________________
> HTH
>
> Bob
>
> "Pawan" <(E-Mail Removed)> wrote in message
> news:CB79315B-1E8E-4CB1-96D6-(E-Mail Removed)...
> > Hi...
> >
> > I am learning about writing macros. I always stuck up at one point.
> > I need to do various activies on columns based on their headings. e.g. I
> > have to replace all "NA" in the column whose heading is "TOWN". Currently
> > I
> > write the macro using column number. But if the columns gets shifted, then
> > this macro will not work. How can I extract column number by identifying
> > its
> > heading?
> >
> > Regards,
> > Pawan

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
lookup using column headers and row headers Memphus01 Microsoft Excel Misc 1 13th Apr 2009 04:57 PM
Hide Column Headers but not row (Headers) Kevan Gradwell Microsoft Excel Programming 1 16th Mar 2007 05:59 PM
Column Headers are numeric as the Row Headers =?Utf-8?B?TWFyayBCdXJzaWFu?= Microsoft Excel Crashes 3 21st Feb 2007 04:56 PM
Dealing with missing headers on mult-pages pages =?Utf-8?B?am9uZWZlcg==?= Microsoft Access Reports 2 6th Jul 2006 04:20 AM
How to set Column headers as row headers in Data grid control =?Utf-8?B?VlIgUmF2aW51dGhhbGE=?= Microsoft Dot NET Framework Forms 1 3rd May 2005 12:25 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:34 PM.