Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do I select a cell based on the Column name

I want to search my spreadsheet for specific values and replace them. As my
sheet is huge I want to start my search in row 1 of a specific column. The
problem is I may add columns in front of the one I am currently using to
start my search and replace. I want to be able to find the column heading
titled "New Deals" and then go to the cell directly below it and begin my
search and replace macro. If the column heading "New Deals" moves from the
5th to the 6th column I still want to be able to use the same macro without
having to go in and change it everytime.

HELP!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 318
Default How do I select a cell based on the Column name

Try this

Public Sub MyFindAndReplace()
Dim r As Range
Dim vSearchFor, vReplaceWith
Dim lLastRow&, lLastCol&

With Sheet1
Set r = .Rows(1).Find(What:="New Deals", LookIn:=xlValues,
LookAt:=xlWhole, MatchByte:=True)
If Not r Is Nothing Then
vSearchFor = InputBox("Enter what you want to search for: ",
"Search For")
If vSearchFor < "" Then
vReplaceWith = InputBox("Enter what you want to replace
with: ", "Replace With")
lLastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
lLastCol = .Cells.SpecialCells(xlCellTypeLastCell).Column
Set r = r.Resize(lLastRow - r.Row, lLastCol - r.Column + 1)
r.Replace What:=vSearchFor, Replacement:=vReplaceWith,
MatchCase:=False
End If
End If
End With
End Sub


"Teresa K." wrote:

I want to search my spreadsheet for specific values and replace them. As my
sheet is huge I want to start my search in row 1 of a specific column. The
problem is I may add columns in front of the one I am currently using to
start my search and replace. I want to be able to find the column heading
titled "New Deals" and then go to the cell directly below it and begin my
search and replace macro. If the column heading "New Deals" moves from the
5th to the 6th column I still want to be able to use the same macro without
having to go in and change it everytime.

HELP!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do I select a cell based on the Column name

Thank you both so much for all your help! You have been totally awesome!

"Alok" wrote:

Try this

Public Sub MyFindAndReplace()
Dim r As Range
Dim vSearchFor, vReplaceWith
Dim lLastRow&, lLastCol&

With Sheet1
Set r = .Rows(1).Find(What:="New Deals", LookIn:=xlValues,
LookAt:=xlWhole, MatchByte:=True)
If Not r Is Nothing Then
vSearchFor = InputBox("Enter what you want to search for: ",
"Search For")
If vSearchFor < "" Then
vReplaceWith = InputBox("Enter what you want to replace
with: ", "Replace With")
lLastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
lLastCol = .Cells.SpecialCells(xlCellTypeLastCell).Column
Set r = r.Resize(lLastRow - r.Row, lLastCol - r.Column + 1)
r.Replace What:=vSearchFor, Replacement:=vReplaceWith,
MatchCase:=False
End If
End If
End With
End Sub


"Teresa K." wrote:

I want to search my spreadsheet for specific values and replace them. As my
sheet is huge I want to start my search in row 1 of a specific column. The
problem is I may add columns in front of the one I am currently using to
start my search and replace. I want to be able to find the column heading
titled "New Deals" and then go to the cell directly below it and begin my
search and replace macro. If the column heading "New Deals" moves from the
5th to the 6th column I still want to be able to use the same macro without
having to go in and change it everytime.

HELP!


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 272
Default How do I select a cell based on the Column name

Sub SearchByColumnHeader()
Dim ColHeader As Range
Dim R As Range
Set ColHeader = Cells.Find(What:="New Deals", _
After:=Range("A1"), LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=True)
If ColHeader Is Nothing Then Exit Sub
Set R = Cells.Find(What:="Next Search Item", _
After:=ColHeader.Offset(1), LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, MatchCase:=True)
R = "Replace Text"
End Sub

That should get you pretty close.
--
Charles Chickering

"A good example is twice the value of good advice."


"Teresa K." wrote:

I want to search my spreadsheet for specific values and replace them. As my
sheet is huge I want to start my search in row 1 of a specific column. The
problem is I may add columns in front of the one I am currently using to
start my search and replace. I want to be able to find the column heading
titled "New Deals" and then go to the cell directly below it and begin my
search and replace macro. If the column heading "New Deals" moves from the
5th to the 6th column I still want to be able to use the same macro without
having to go in and change it everytime.

HELP!


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Range based on column name and not A1 notations T.Vidak Excel Discussion (Misc queries) 3 July 16th 08 02:02 PM
Help tonight?!! select rows based on cell value in a column Lighthouse1 Excel Worksheet Functions 1 January 31st 07 02:57 AM
Select a column based on a index VH Excel Programming 5 March 6th 06 09:40 AM
Select a column based on a cell entry [email protected] Excel Programming 2 September 29th 05 12:41 PM
Macro to select rows based on a value in a column raceachvy Excel Programming 2 July 12th 05 12:14 AM


All times are GMT +1. The time now is 05:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"