View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Selecting Columns by Title

Does that mean you have the RC characters in a cell in row 1 and want to select
that column?

Option Explicit
Sub testme()
Dim FoundCell As Range
Dim WhatToFind As String

WhatToFind = "RC"

With Worksheets("Sheet1")
With .Rows(1)
Set FoundCell = .Cells.Find(What:=WhatToFind, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=True)
End With
End With

If FoundCell Is Nothing Then
MsgBox "No " & WhatToFind & " found in row 1"
Exit Sub
End If

FoundCell.EntireColumn.Select

End Sub


Jessica wrote:

I am writing a macro to select columns based on their title.

If I always wanted to select Column D, then I could use:
Columns("D:D").Select

But in my case, I want to select a column that is titled "RC". I tried to
replace "D:D" with "RC", but I get an error.

Thanks,
Jessica


--

Dave Peterson