LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Find/replace macro

How about just using Find?

Option Explicit
Sub testme()

Dim myWord As String
Dim FirstAddress As String
Dim FoundCell As Range

myWord = Worksheets("data").Range("a1").Value

With Worksheets("table").Range("b:b")
Set FoundCell = .Cells.Find(What:=myWord, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

If FoundCell Is Nothing Then
'do nothing--not found
Else
FirstAddress = FoundCell.Address
Do
With FoundCell.Offset(0, 4)
.Value = "y"
With .Font
.Name = "Century Gothic"
.FontStyle = "Regular"
.Size = 9
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
End With
Set FoundCell = .FindNext(FoundCell)
Loop While Not FoundCell Is Nothing _
And FoundCell.Address < FirstAddress
End If
End With
End Sub



VB Newbie wrote:

Hi guys,

I have two sheets I am dealing with right now: Data and Table. I am trying
to create a macro to locate a cell content, say Data:A1, finding it in column
B range in Table, and moving four cells to the right of it (adding the
character "y" to it). I've tried to use autofilter and find that way as
well, but that didn't seem to work either.

Here is my script below. Where it says Criteria1:="=510", that should be
the cell contents in Data:A1. Any help that can be offered will be greatly
appreciated.

Sub MyMacro()

Range("C2").Select
Selection.Copy
Sheets("Table").Select
Rows("2:2").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.AutoFilter
ActiveWindow.SmallScroll ToRight:=-1
Sheets("Data").Select
Range("C2").Select
Selection.Copy
Sheets("Table").Select
Selection.AutoFilter Field:=2, Criteria1:="=510", Operator:=xlAnd
Range("F8").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "y"
With ActiveCell.Characters(Start:=1, Length:=1).Font
.Name = "Century Gothic"
.FontStyle = "Regular"
.Size = 9
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Range("F88").Select
Selection.AutoFilter
Sheets("Data").Select
Range("C2").Select
End Sub


--

Dave Peterson
 
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
Find and replace macro edeaston Excel Discussion (Misc queries) 3 January 12th 09 10:51 AM
Macro to Find and Replace R Storey Excel Discussion (Misc queries) 6 December 6th 06 07:04 PM
Macro to Find & Replace [email protected] Excel Worksheet Functions 2 September 14th 06 07:17 PM
find&replace macro Elainey Excel Worksheet Functions 0 January 6th 06 09:20 PM
find and replace macro need help excelguru Excel Programming 3 April 30th 04 04:26 AM


All times are GMT +1. The time now is 11:12 PM.

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"