Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-09-2012, 09:18 AM
vthomeschoolmom vthomeschoolmom is offline VBA column header vs first row text Windows 7 32bit VBA column header vs first row text Office 2010 32bit
Novice
VBA column header vs first row text
 
Join Date: Feb 2012
Posts: 23
vthomeschoolmom is on a distinguished road
Default VBA column header vs first row text

I want to perform an action on rows within a column. I want to get the column header letter(s) of the column whose first row contains a known value.

For instance, if the first row of column N shows "Price", I want to retrieve the N for using in a range select. The columns that I will be working with are not fixed.



Can someone help the Excel object model noob with this? Muchos gracias.
Reply With Quote
  #2  
Old 03-10-2012, 02:05 AM
macropod's Avatar
macropod macropod is offline VBA column header vs first row text Windows 7 64bit VBA column header vs first row text Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could try something along the lines of:
Code:
Sub Demo()
Dim LastCol As Long, i As Long
With ActiveSheet
  LastCol = .Cells.SpecialCells(xlCellTypeLastCell).Column
  For i = 1 To LastCol
    If .Cells(1, i).Value = "Price" Then Exit For
  Next
  MsgBox Split(.Cells(1, i).Address, "$")(1)
End With
End Sub
Of course, you don't actually need the column letter(s) to work with the column. Having found the column number, you can work with that. For example, if you want a value from the 10th row in the found column, you could use:
.Cells(10, i).Value
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Two column format without affecting neither the page numbers nor the header or footer Jamal NUMAN Word 4 02-21-2012 03:20 PM
VBA column header vs first row text Aligning column text in a table dpeattie Word 6 12-29-2010 04:59 PM
adding text on a separated column line ahmet1985 Word 0 03-27-2010 07:10 AM
VBA column header vs first row text 2-Column Text Slides and Aligning Bullets KitKatJM PowerPoint 1 03-09-2010 06:45 PM
Lost Column header Policy Peddler Outlook 1 06-05-2009 07:57 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:29 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft